我在shinyBS::bsCollapsePanel中使用一个shinyBS::bsCollapsePanel。我的应用程序中有逻辑,这取决于哪个shinyBS面板是活动的(即扩展的)。这很好,直到我激活条件面板。如果我显示了闪亮的条件面板,那么即使面板是非活动的(即关闭的),shinyBS折叠面板也会陷入活动状态。
如何修改代码,使可折叠面板仅在展开时注册为活动面板?
在本例中,有一个文本输出指示活动面板。除非显示条件面板,否则面板之间的切换工作正常。
编辑:看起来这个bug可能已经有文档化(https://github.com/ebailey78/shinyBS/issues/38),并且有一个可能的解决方案(https://github.com/ebailey78/shinyBS/pull/68/commits)。
library(shiny)
library(shinyBS)
# Define UI logic
ui <- fluidPage(
htmlOutput("activePanel"),
shinyBS::bsCollapse(
id = "bsPanels",
shinyBS::bsCollapsePanel(
"Panel A",
value = "panelA",
checkboxInput("showPanelA",
"Show panel",
value = FALSE),
conditionalPanel(
condition = "input.showPanelA",
helpText("Panel A conditional content")
),
helpText("Panel A main content")
),
shinyBS::bsCollapsePanel(
"Panel B",
value = "panelB",
checkboxInput("showPanelB",
"Show panel",
value = FALSE),
conditionalPanel(
condition = "input.showPanelB",
helpText("Panel B conditional content")
),
helpText("Panel B main content")
)
)
)
# Define server logic
server <- function(input, output) {
output$activePanel <- renderText({
paste("<b>Active Panel:</b>", paste(input$bsPanels, collapse = ", "))
})
}
# Run the application
shinyApp(ui = ui, server = server)发布于 2019-09-19 20:06:29
在shinyBS项目页面(https://github.com/ebailey78/shinyBS/issues/38)上有一些关于这个问题的讨论。然而,我在提出的解决办法方面取得了有限的成功。
我找到的最佳解决方案是使用shinyjs::showElement和shinyjs::hideElement。
library(shiny)
library(shinyBS)
library(shinyjs)
# Define UI logic
ui <- fluidPage(
useShinyjs(),
htmlOutput("activePanel"),
shinyBS::bsCollapse(
id = "bsPanels",
shinyBS::bsCollapsePanel(
"Panel A",
value = "panelA",
checkboxInput("showPanelA",
"Show panel",
value = FALSE),
uiOutput("condPanelA"),
helpText("Panel A main content")
),
shinyBS::bsCollapsePanel(
"Panel B",
value = "panelB",
checkboxInput("showPanelB",
"Show panel",
value = FALSE),
uiOutput("condPanelB"),
helpText("Panel B main content")
)
)
)
# Define server logic
server <- function(input, output) {
output$activePanel <- renderText({
paste("<b>Active Panel:</b>", paste(input$bsPanels, collapse = ", "))
})
# Logic for conditional panels
output$condPanelA <- renderUI({
helpText("Panel A conditional content")
})
observe({
if(input$showPanelA) {
show("condPanelA")
} else {
hide("condPanelA")
}
})
output$condPanelB <- renderUI({
helpText("Panel B conditional content")
})
observe({
if(input$showPanelB) {
show("condPanelB")
} else {
hide("condPanelB")
}
})
}
# Run the application
shinyApp(ui = ui, server = server)https://stackoverflow.com/questions/58015021
复制相似问题