Skip to content

Instantly share code, notes, and snippets.

@timelyportfolio
Last active February 9, 2022 03:59
Show Gist options
  • Select an option

  • Save timelyportfolio/b8001318ce3e25b6920a0f20e9db374e to your computer and use it in GitHub Desktop.

Select an option

Save timelyportfolio/b8001318ce3e25b6920a0f20e9db374e to your computer and use it in GitHub Desktop.

Revisions

  1. timelyportfolio revised this gist Jul 4, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion example.R
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ browsable(tagList(
    rhandsontable(
    data = mtcars,
    rowHeaders = NULL,
    // see http://jsfiddle.net/pn3rv48p/ for another example with afterGetColHeader
    # see http://jsfiddle.net/pn3rv48p/ for another example with afterGetColHeader
    afterGetColHeader = htmlwidgets::JS(htmltools::HTML(
    sprintf(
    "
  2. timelyportfolio revised this gist Jul 4, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions example.R
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,8 @@ sprintf(
    "
    function(i, TH) {
    var titleLookup = %s;
    // destroy previous tippy instance if it exists
    if(TH.hasOwnProperty('_tippy')) {TH._tippy.destroy()}
    // initialize tooltip and set content to description from our titleLookup
    tippy(TH, {
    content: titleLookup[i].desc,
  3. timelyportfolio created this gist Jul 4, 2020.
    51 changes: 51 additions & 0 deletions example.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    library(rhandsontable)
    library(htmltools)

    browsable(tagList(
    rhandsontable(
    data = mtcars,
    rowHeaders = NULL,
    // see http://jsfiddle.net/pn3rv48p/ for another example with afterGetColHeader
    afterGetColHeader = htmlwidgets::JS(htmltools::HTML(
    sprintf(
    "
    function(i, TH) {
    var titleLookup = %s;
    // initialize tooltip and set content to description from our titleLookup
    tippy(TH, {
    content: titleLookup[i].desc,
    });
    }
    ",
    # use column information from ?mtcars
    # sprintf will place this json array of objects in our script above at %s
    jsonlite::toJSON(
    read.delim(
    textConnection('
    [, 1] mpg Miles/(US) gallon
    [, 2] cyl Number of cylinders
    [, 3] disp Displacement (cu.in.)
    [, 4] hp Gross horsepower
    [, 5] drat Rear axle ratio
    [, 6] wt Weight (1000 lbs)
    [, 7] qsec 1/4 mile time
    [, 8] vs Engine (0 = V-shaped, 1 = straight)
    [, 9] am Transmission (0 = automatic, 1 = manual)
    [,10] gear Number of forward gears
    [,11] carb Number of carburetors'
    ),
    header = FALSE,
    col.names = c("loc","id","desc"),
    stringsAsFactors = FALSE
    ),
    auto_unbox = TRUE
    )
    )
    ))
    ),
    # use tippy/bootstrap since Bootstrap 3 tooltips are awful
    # and don't place nicely with handsontable
    # better with htmlDependency but this works fine
    tags$script(src = "https://unpkg.com/@popperjs/core@2"),
    tags$script(src = "https://unpkg.com/tippy.js@6")
    ))