2

The dynamic popover from shinyBS only turns up on every second selection.

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)
Dieter Menne
  • 10,076
  • 44
  • 67

2 Answers2

3

This is a known bug in Bootstrap:

Bootstrap popover destroy & recreate works only every second time

If you do not want to change the code of ShinyBS, 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"))),
Community
  • 1
  • 1
Dieter Menne
  • 10,076
  • 44
  • 67
2

I might have found a simpler solution, using removePopover() and Sys.sleep(0.2) before calling addPopover().

observeEvent(input$poppy, {
     removePopover(session, "poppy")
     Sys.sleep(0.2)
     poppy = paste("You selected ", input$poppy)
     addPopover(session, "poppy", "Every second time", poppy)
})

This works for me without the need of the pop_patch.js file

Ayoros
  • 21
  • 3