ebailey78 / shinyBS

Twitter Bootstrap Components for Shiny
182 stars 47 forks source link

bsTooltip() not working with shinyWidgets::switchInput() #117

Open leungi opened 4 years ago

leungi commented 4 years ago

Reprex below.

Changing the trigger args in bsTooltip() doesn't solve it.

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

## Only run examples in interactive R sessions
if (interactive()) {

  # Examples in the gallery :
  shinyWidgets::shinyWidgetsGallery()

  # Basic usage :
  ui <- fluidPage(
    switchInput(inputId = "somevalue",      
                value = TRUE,
                onLabel = "Yes",
                offLabel = "No"),
    bsTooltip("somevalue",
              "Test Me",
              "right"
    ),
    verbatimTextOutput("value")
  )
  server <- function(input, output) {
    output$value <- renderPrint({ input$somevalue })
  }
  shinyApp(ui, server)
}

bstooltip-error

svalvaro commented 3 years ago

Hey @leungi did you solve this?

svalvaro commented 3 years ago

If anyone runs into this problem I found a workaround with divs:

tags$div(
title = "This title will be the tooltip, write whatever you want",

  shinyWidgets::switchInput(inputId = "somevalue",      
                value = TRUE,
                onLabel = "Yes",
                offLabel = "No")
)
latlio commented 3 years ago

@svalvaro I'm not sure I follow your response. Are you saying that the title of tags$div will be the text of the tooltip. Where is bsTooltip in your solution?

svalvaro commented 3 years ago

@latlio Exactly, the title will be the tooltip. That's the good thing, you don't need bsTooltip. I came out with this solution since bsTooltip was not working for me. I hope it helps.

latlio commented 3 years ago

Thanks @svalvaro! For documentation on this thread, the behavior behind @svalvaro's solution is the global HTML title attribute. Note that the time it takes between mouse hover and appearance of tooltip will be browser-dependent, unlike the "instantaneous" response of bsTooltip. It's still unclear why bsTooltip() is not working.

actuarial-lonewolf commented 1 year ago

A better solution is to assign an ID to the div, and call that ID in the bsTooltip()

This is the "instantaneous" response of bsTooltip you are looking for.

tags$div(
  shinyWidgets::switchInput(inputId = "somevalue",      
                value = TRUE,
                onLabel = "Yes",
                offLabel = "No")
, id= "somevalue_div")

bsTooltip(id = "somevalue_div", 
          title = "Your bubble text title",
          placement = "top")