[英]Shiny popover from shinyBS displays every second time only
The dynamic popover from shinyBS only turns up on every second selection.来自 ShinyBS 的动态弹出框仅在每第二个选择时出现。
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)
This is a known bug in Bootstrap:这是 Bootstrap 中的一个已知错误:
Bootstrap popover destroy & recreate works only every second time Bootstrap popover destroy & recreate 仅每两次工作一次
If you do not want to change the code of ShinyBS, add a js file with the following in your www subfolder:如果不想更改 ShinyBS 的代码,请在 www 子文件夹中添加一个包含以下内容的 js 文件:
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)并将以下内容添加到您的 ui 中:(假设文件名为 pop_patch.js)
singleton(tags$head(tags$script(src = "pop_patch.js"))),
I might have found a simpler solution, using removePopover() and Sys.sleep(0.2) before calling addPopover().我可能找到了一个更简单的解决方案,在调用 addPopover() 之前使用 removePopover() 和 Sys.sleep(0.2)。
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这对我有用,不需要 pop_patch.js 文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.