【发布时间】:2017-09-16 02:18:56
【问题描述】:
我的问题与观察在 shinyBS 中的 bsCollapsePanel 中切换和取消切换标题的事件有关。
让我们以以下应用为例:
library(shiny)
library(shinyBS)
server = function(input, output, session) {
observeEvent(input$p1Button, ({
updateCollapse(session, "collapseExample", open = "Panel 1")
}))
observeEvent(input$styleSelect, ({
updateCollapse(session, "collapseExample", style = list("Panel 1" = input$styleSelect))
}))
output$randomNumber <- reactive(paste0('some random number'))
}
ui = fluidPage(
sidebarLayout(
sidebarPanel(HTML("This button will open Panel 1 using <code>updateCollapse</code>."),
actionButton("p1Button", "Push Me!"),
selectInput("styleSelect", "Select style for Panel 1",
c("default", "primary", "danger", "warning", "info", "success"))
),
mainPanel(
bsCollapse(id = "collapseExample", open = "Panel 2",
bsCollapsePanel("Panel 1", "This is a panel with just text ",
"and has the default style. You can change the style in ",
"the sidebar.", style = "info")
),
verbatimTextOutput('randomNumber')
)
)
)
app = shinyApp(ui = ui, server = server)
我希望应用能够在每次通过单击 Panel 1 标题打开 bsCollapsePanel 时在 verbatimTextOutput('randomNumber') 字段中打印一个随机数(使用 R 闪亮反应性)。
我在想也许可以使用shinyjs 包,但没有找到很多这两个包一起使用的例子。
【问题讨论】:
标签: javascript r shiny shinyjs shinybs