0

Let us say I something as follows using DT and Shiny. Now, I want to add "hover text" over any cell of any column, and the hover text itself should be column specific, showing "mean / SD" values for that column of data. In this case, separate "mean / SD" values per mpg, wt and hp columns.

How can I do that? Not, I will be constructing the "mean / SD" hover text from values in a separate "reference" metrics dataframe, and NOT from the data in the DT table.

library(dplyr)
library(shiny)
library(DT)

ui <- fluidPage(
  DT::dataTableOutput('mtcarsdata')
)

server <- function(input, output, session) {
  output$mtcarsdata <- DT::renderDataTable(
    select(head(mtcars), mpg, wt, hp)  
  )
}

shinyApp(ui = ui, server = server)

Then, my reference data frame from which the hover text would be constructed looks something like this:

ref <- tibble(mpgmean = 33.9, mpgsdd = 4.9, wtmean = 0.38, wtsd = .063, hpmean = 134, hpsd = 22)
ref
# A tibble: 1 × 6
  mpgmean mpgsdd wtmean  wtsd hpmean  hpsd
    <dbl>  <dbl>  <dbl> <dbl>  <dbl> <dbl>
1    33.9    4.9   0.38 0.063    134    22
Gopala
  • 10,363
  • 7
  • 45
  • 77
  • 2
    Maybe you could try to adapt that: . Personally I prefer having the tooltips in the headers only. – Stéphane Laurent Jul 06 '23 at 22:56
  • That sounded good. But, I found the solution here to exactly what I am looking for, including coloring cells. It is a simpler solution too. https://stackoverflow.com/questions/58296972/r-using-javascript-to-customize-dt-tables – Gopala Jul 10 '23 at 20:54

0 Answers0