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