-->

Hover Tool Tip over DataTable value in R?

2019-08-28 18:03发布

问题:

Is there any way to get a hover tool tip working on a shiny data table that has some information, this is possible on graphs but never seen it done before on a data table

回答1:

Yes, like this (no need of Shiny):

library(DT)
datatable(head(iris), 
          options=list(initComplete = JS(c(
            "function(settings){",
            "  var table = settings.oInstance.api();",
            "  var cell = table.cell(2,2);",
            "  cell.node().setAttribute('title', 'TOOLTIP CONTENTS');",
            "}")))
)

table.cell(2,2) means the cell at row 2 and column 2; indices start at 0 in Javascript, and the column of row names is taken into account.