首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >shinyBS::bsCol体与闪亮::条件面板之间的冲突

shinyBS::bsCol体与闪亮::条件面板之间的冲突
EN

Stack Overflow用户
提问于 2019-09-19 16:05:55
回答 1查看 409关注 0票数 1

我在shinyBS::bsCollapsePanel中使用一个shinyBS::bsCollapsePanel。我的应用程序中有逻辑,这取决于哪个shinyBS面板是活动的(即扩展的)。这很好,直到我激活条件面板。如果我显示了闪亮的条件面板,那么即使面板是非活动的(即关闭的),shinyBS折叠面板也会陷入活动状态。

如何修改代码,使可折叠面板仅在展开时注册为活动面板?

在本例中,有一个文本输出指示活动面板。除非显示条件面板,否则面板之间的切换工作正常。

编辑:看起来这个bug可能已经有文档化(https://github.com/ebailey78/shinyBS/issues/38),并且有一个可能的解决方案(https://github.com/ebailey78/shinyBS/pull/68/commits)。

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2019-09-19 20:06:29

在shinyBS项目页面(https://github.com/ebailey78/shinyBS/issues/38)上有一些关于这个问题的讨论。然而,我在提出的解决办法方面取得了有限的成功。

我找到的最佳解决方案是使用shinyjs::showElementshinyjs::hideElement

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58015021

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档