I'm writing a shiny app with the help of 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 name of the column.
Here is an 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 to have sth like this, when you move the courser over the Species column name:
Is it even possible? Please help.
Thanks to this I managed to make an output 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 makes explanation boxes defined in JavaScript variable tips
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With