Search code examples
rshinyshinybs

Delaying and expiring a shinyBS::bsTooltip


Is it possible to delay a tooltip and expire after a few seconds?

require(shiny)
require(shinyBS)

shinyApp(ui = fluidPage(
  shinyjs::useShinyjs(),
  bsTooltip(id = 'input', title = "Lets delay this appearing for 1s and force disappear after 5s", 
    placement = "bottom", trigger = "hover", options = list(delay = list(show=1000, hide=3000))),

  sidebarLayout(
    sidebarPanel(
      selectInput(inputId = 'input', label = 'input', choices = c('cats','dogs'))
    ),
    mainPanel()
  )
)
, server = function(input, output){})

enter image description here


Solution

  • shinyBS::bsTooltip fails to properly serialize nested options lists in https://github.com/ebailey78/shinyBS/blob/shinyBS3/R/Tooltips_and_Popovers.R#L129

    The options object ends up looking like { delay: "list(show = 1000, hide = 3000)" }

    Unfortunately it looks like shinyBS isn't maintained anymore, or a fix would be worth submitting.

    I'll suggest a workaround - using shinyBS::addTooltip which does serialize options correctly.

    require(shiny)
    require(shinyBS)
    
    shinyApp(
      ui = fluidPage(
        # shinyjs::useShinyjs(),
        shinyBS:::shinyBSDep,
    
        sidebarLayout(
          sidebarPanel(
            selectInput(inputId = 'input', label = 'input', choices = c('cats','dogs'))
          ),
          mainPanel()
        )
      ),
      server = function(input, output, session) {
        addTooltip(session, id = 'input', title = "Lets delay this appearing for 1s and force disappear after 5s",
                   placement = "bottom", trigger = "hover", options = list(delay = list(show=1000, hide=3000)))
      }
    )
    

    Or just using Bootstrap directly.