0

I'm trying to add a hover-over text to my shiny app. Specifically, I want to add it to the label of the virtualSelectInput (which is the label above the drop-down selection).

I have found posts on how to add hover-over text to the CHOICES in the drop down selection, but so far I haven't been able to find anything that shows how to do this with the label itself. Any ideas would be greatly appreciated!

Relevant part of my code:

div(
    useShinyjs(),
     virtualSelectInput(
      inputId = ns("benchmark_population"),
      label = "Select Benchmark Population: ",
      choices = NULL,
      selected = NULL,
      multiple = FALSE,
      search = FALSE,
      placeholder = "Benchmark Population"
    ),

So far, I've tried various approaches such as shinyWidgets::pickerInput instead of virtualSelectInput and then shiny::p("This is the sub-title for the benchmark population selection"), neither of which are doing the trick.

Em Reit
  • 1
  • 1

2 Answers2

0

A simple hack would be to lean on the html title attribute. When you hover over the div you'll see the title.

This is untested since no reproducible data was provided.

div(
    title = "Test Benchmark Population", # add a title to the div
    useShinyjs(),
     virtualSelectInput(
      inputId = ns("benchmark_population"),
      label = "Select Benchmark Population: ",
      choices = NULL,
      selected = NULL,
      multiple = FALSE,
      search = FALSE,
      placeholder = "Benchmark Population"
    ),

Example

library(shiny)

ui <- fluidPage(
  div(
    title = "this is a test",
    selectInput("test",label = "Test",choices = 1:5, selected = 1)
  )
)
server <- function(input, output, session) {}

shinyApp(ui, server)
Jamie
  • 1,793
  • 6
  • 16
0

If the input ID of your virtualSelect is MYID then the label ID is MYID-label. Once you have a HTML id on an element, you can use bsTooltip in the package shinyBS.

library(shiny)
library(shinyWidgets)
library(shinyBS)

ui <- fluidPage(
  virtualSelectInput(
    inputId = "MYID",
    label = "Single select :",
    choices = month.name,
    search = TRUE
  ),
  bsTooltip(
    id = "MYID-label",
    "Hello select something please"
  )
)

server <- function(input, output) {}

shinyApp(ui, server)
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225