r - Datatable tooltip from another column -


how add tooltip (or mouseover popup) cells of datatable, pulls data column?

for example if display first 3 columns of mtcars in datable, how display tooltip hp (horsepower) data of car name hovering on mouse?

there similar questions on how can display static text tooltip, can't find way display data column toolptip.

#ui.r library(shiny) library(dt) shinyui(   mainpanel(     dt::datatableoutput("tbl")   )    )      #server.r  library(shiny) library(dt) shinyserver(function(input, output,session) {   output$tbl = dt::renderdatatable(     datatable(mtcars[, 1:3])) })  

to tooltip hp can modify server code follows:

   shinyserver(function(input, output,session) {     output$tbl <- dt::renderdatatable({       datatable(mtcars[, 1:4], options = list(rowcallback = js(         "function(nrow, adata, idisplayindex, idisplayindexfull) {",         "var full_text = adata[4]",         "$('td:eq(0)', nrow).attr('title', full_text);",         "$('td:eq(1)', nrow).attr('title', full_text);",         "$('td:eq(2)', nrow).attr('title', full_text);",         "$('td:eq(3)', nrow).attr('title', full_text);",         "}"),          columndefs = list(list(visible=false, targets=c(4)))       )       )     })    })  

the js code adds tooltip first 4 columns value of hp column. here dataset contains hp column hiding column using columndefs parameter.

hope helps!


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

minify - Minimizing css files -

php - How to remove letter in front of the word laravel -