Hover Tool Tip over DataTable value in R?

2019-08-28 17:47发布

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条回答
SAY GOODBYE
2楼-- · 2019-08-28 18:00

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.

enter image description here

查看更多
登录 后发表回答