vladli
vladli

Reputation: 1573

add shinyBS popover on disabled button

I haven't found any information in documentation of shinyBS and on the google/SO about how to use trigger = 'manual' on, for example, addPopover of shinyBS. I thought this would be the way to add a tooltip to a disabled button. (I dont want to do it with div'ving the button and giving title to div. Also would be nice if someone has a way to add tooltips reactively to shiny apps

Upvotes: 1

Views: 1432

Answers (2)

shosaco
shosaco

Reputation: 6165

If you want to use trigger = manual on the popover, then you need to define a script to toggle the popover, e.g. with jQuery:

library(shiny)
library(shinyjs)
library(shinyBS)


ui <-shinyUI(fluidPage(useShinyjs(),
                       # press this button to trigger the popover
                       actionButton("addPopover", "Add Popover"),
                       
                       # a disabled button
                       disabled(actionButton("disabledButton", "This button is disabled")),
                       
                       # the popover to appear over the disabled button
                       bsPopover("disabledButton", "Popover", "Some text", trigger="manual"),
                       
                       # the script to trigger the popover
                       uiOutput("trigger")))


server <- shinyServer(function(input,output, session){
  
  # on checkbox selection, disable button and trigger the popover
  output$trigger <- renderUI({
    input$addPopover
    tags$script("$('#disabledButton').popover('toggle');")
  })
})

shinyApp(ui,server)

Upvotes: 2

vladli
vladli

Reputation: 1573

Since shosaco's solution didnt work for me, I got it to work this way:

if (input$disable) { 
  addCssClass("buttonId", "disabled")
  bsTooltip("buttonId", "This button is currently disabled.")
} else {
  bsTooltip("buttonId", "")
  removeCssClass("buttonId", "disabled")
}
observeEvent(input$buttonId, {
    if (!input$disable) {
      output$text <- renderText("Bla")
    } else {
      output$text <- renderText(NULL)
    }

Upvotes: -2

Related Questions