我在shinyBS
的文档和google/SO上没有找到任何关于如何使用trigger = 'manual'
的信息,例如,addPopover
shinyBS
。我认为这将是向禁用按钮添加工具提示的方法。(我不想用div
'按下按钮并给div
title
来做到这一点。 如果有人有办法被动地将工具提示添加到shiny
应用程序中,那就太好
如果你想在弹出框上使用trigger = manual
,那么你需要定义一个脚本来切换弹出框,例如使用 jQuery:
library(shiny)
library(shinyjs)
library(shinyBS)
ui <-shinyUI(fluidPage(useShinyjs(),
# press this button to trigger the popover
actionButton("addPopover", "Add Popover"),
# a disabled button
disabled(actionButton("disabledButton", "This button is disabled")),
# the popover to appear over the disabled button
bsPopover("disabledButton", "Popover", "Some text", trigger="manual"),
# the script to trigger the popover
uiOutput("trigger")))
server <- shinyServer(function(input,output, session){
# on checkbox selection, disable button and trigger the popover
output$trigger <- renderUI({
input$addPopover
tags$script("$('#disabledButton').popover('toggle');")
})
})
shinyApp(ui,server)
由于 shosaco 的解决方案对我不起作用,所以我让它以这种方式工作:
if (input$disable) {
addCssClass("buttonId", "disabled")
bsTooltip("buttonId", "This button is currently disabled.")
} else {
bsTooltip("buttonId", "")
removeCssClass("buttonId", "disabled")
}
observeEvent(input$buttonId, {
if (!input$disable) {
output$text <- renderText("Bla")
} else {
output$text <- renderText(NULL)
}