在禁用按钮上添加 shinyBS 弹出窗口
add shinyBS popover on disabled button
我没有在 shinyBS
和 google/SO 的文档中找到任何关于如何在 addPopover
上使用 trigger = 'manual'
的信息10=]。我认为这将是向禁用按钮添加工具提示的方法。 (我不想用 div
按下按钮并将 title
给 div
。
如果有人有办法将工具提示反应性地添加到 shiny
apps
也很好
如果你想在弹窗上使用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)
由于 的解决方案对我不起作用,我以这种方式解决:
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)
}
我没有在 shinyBS
和 google/SO 的文档中找到任何关于如何在 addPopover
上使用 trigger = 'manual'
的信息10=]。我认为这将是向禁用按钮添加工具提示的方法。 (我不想用 div
按下按钮并将 title
给 div
。
如果有人有办法将工具提示反应性地添加到 shiny
apps
如果你想在弹窗上使用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)
由于
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)
}