How can you add an explanation to a shiny data column?

I am writing a brilliant application using datatables, and I would like to make small boxes that will explain what each column means. Ideally, I would like them to appear when you move the cursor over the column name.

Here is the app:

ui.R

library(shiny) data(iris) shinyUI(fluidPage( sidebarLayout( sidebarPanel( fluidRow( column(12, wellPanel( radioButtons("species", label="Species:", choices=levels(iris$Species), selected=levels(iris$Species)[1] ) ) ) ) ), mainPanel( fluidRow(column(12, dataTableOutput("table1") ) ) ) ) ) ) 

server.R

 library(shiny) library(dplyr) library(tidyr) data(iris) shinyServer(function(input, output) { iris1 <- reactive({ iris %>% filter(Species %in% input$species) }) output$table1 <- renderDataTable({ iris1() }) }) 

And I would like this to be the case when you move the cursor over the Species column name: enter image description here

Is it possible? Please, help.

+5
source share
1 answer

Thanks to this, I was able to draw the conclusion I wanted:

ui.R - without any changes

server.R

 library(shiny) library(dplyr) library(tidyr) data(iris) shinyServer(function(input, output) { iris1 <- reactive({ iris %>% filter(Species %in% input$species) }) output$table1 <- renderDataTable(iris1(), callback = htmlwidgets::JS(" var tips = ['Row Names', 'The Sepal Length', 'The Sepal Width', 'The Petal Length', 'The Petal Width'], header = table.columns().header(); for (var i = 0; i < tips.length; i++) { $(header[i]).attr('title', tips[i]); } ")) }) 

It creates explanation fields defined in the JavaScript tips variable.

+3
source

Source: https://habr.com/ru/post/1232096/


All Articles