block by timelyportfolio 78c668d3ba8a46f0570298bc910d1a2e

R formattable + tooltipsterR for table cell tooltips

Full Screen

This StackOverflow discussion covers what I think is a fairly typical use case of adding tooltips to html table cells. Here is a very quick example combining formattable with tooltipsterR.

Example

bl.ocks

Code

library(htmltools)
library(formattable)
library(tooltipsterR)

ft <- formattable(
  mtcars,
  formatters = structure(
    lapply(
      colnames(mtcars),
      function(col){
        formatter(
          "span",
          "class" = "cell-tooltip",
          "title" = x~paste("tooltip for ",col,": ",x),
          x~x
        )
      }
    ),
    names=colnames(mtcars)
  )
)

browsable(
  tagList(
    as.htmlwidget(ft),
    tooltipster(selector=".cell-tooltip")
  )
)