ebailey78 / shinyBS

Twitter Bootstrap Components for Shiny
182 stars 47 forks source link

Shiny popover from shinyBS displays every second time only #88

Open dmenne opened 7 years ago

dmenne commented 7 years ago

This was posted on: http://stackoverflow.com/questions/43491305/shiny-popover-from-shinybs-displays-every-second-time-only

but there was no reply. I first thought it was an error of mine, but it looks more like a bug to me now.

library(shiny)
library(shinyBS)

ui <- fluidPage(
   sidebarLayout(
      sidebarPanel(
        selectInput("poppy", "Think!", c("A", "B", "C", "D")),
        bsButton("dummy", "dummy")), ## required, dummy
      mainPanel(
        helpText("Note that when you select from the box, popover turns up every second time only!")
)))

server <- function(input, output, session) {
   observe({
     poppy = paste("You selected ", input$poppy)
     addPopover(session, "poppy", "Every second time", poppy)
})}

shinyApp(ui = ui, server = server)
dmenne commented 7 years ago

This is a know bug in bootstrap:

http://stackoverflow.com/questions/27238938/bootstrap-popover-destroy-recreate-works-only-every-second-time

If you do not want to change the code (and pull requests go unanswered), add a js file with the following in your www subfolder:

shinyBS.addTooltip = function(id, type, opts) {
  var $id = shinyBS.getTooltipTarget(id);
  var dopts = {html: true};
  opts = $.extend(opts, dopts);

  if(type == "tooltip") {
    $id.tooltip("destroy");
    setTimeout(function() {$id.tooltip(opts);},200);
  } else if(type == "popover") {
    $id.popover("destroy");
    setTimeout(function() {$id.popover(opts);},200);
  }
}

and add the following to your ui: (assuming the file is named pop_patch.js)

singleton(tags$head(tags$script(src = "pop_patch.js"))),

professorbeautiful commented 6 years ago

Thanks, I was struggling with this!