我的問題涉及觀察切換和取消切換閃爍BS中bsCollapsePanel標題的事件。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)
我希望應用程序能夠通過點擊在verbatimTextOutput('randomNumber')
場每次我打開bsCollapsePanel
一次打印一個隨機數(,使用R閃亮的反應性) Panel 1
標題。
我在想這可能使用shinyjs
包,但沒有找到這兩個包一起使用的很多例子。
優雅的解決方案。即使在運行之後,我也意識到我希望數字在我關閉面板後改變。但是因爲我只提到在我的問題中打開小組,所以你是第一個回答這個問題的小組對我來說是合情合理的。 – user974514
我將不勝感激。隨意發佈另一個關於附加要求的問題,我相信有人會解決它 - 包括我,如果我找到時間。 –