【问题标题】:bsCollapsePanel within renderUIrenderUI 中的 bsCollapsePanel
【发布时间】:2017-09-21 22:26:20
【问题描述】:

我在我正在开发的应用程序中大量使用bsCollapse 面板(来自shinyBS 库)。我希望能够在服务器端定义一个面板,如代码所示。代码不运行并返回错误ERROR: argument is of length zero。问题似乎是 bsCollapse 不会接受 renderUI 参数,并且需要在 ui.R 中调用 bsCollapsePanel。

我已经尝试在服务器端使用bsCollapse(),它可以工作但很笨重,因为各个面板不会以相同的方式展开/折叠。我也试过包括outputOptions(output, "hipanel", suspendWhenHidden = FALSE),这个想法是我的“hipanel”会更早地被评估,但这没有用。

我认为关键是 renderUI/uiOutput 没有返回 bsCollapsePanel 接受的对象(至少不是在正确的时间),但我不知道该怎么办。

服务器.R

shinyServer(function(input, output){
    output$hipanel<-renderUI({
        bsCollapsePanel("hello",helpText("It's working!"))
    })
  })

ui.R

shinyUI(fluidPage(
    mainPanel(
        bsCollapse(
            bsCollapsePanel("This panel works",helpText("OK")),
            uiOutput("hipanel")
    ))))

【问题讨论】:

    标签: shiny


    【解决方案1】:

    似乎bsCollapse 需要bsCollapsePanel,所以只需将其添加,然后您就可以在内容中找到任何您想要的内容:

    library(shiny)
    library(shinyBS)
    
    ui <- shinyUI(fluidPage(
      mainPanel(
        bsCollapse(
          bsCollapsePanel("This panel works",helpText("OK")),
          bsCollapsePanel("hello",uiOutput("hipanel"))
        )
      )))
    
    
    server <- shinyServer(function(input, output,session){
    
      output$hipanel<- renderUI({
        helpText("It's working!")
      })
    })
    
    
    shinyApp(ui,server)
    

    你总是可以动态地创建整个东西

    library(shiny)
    library(shinyBS)
    
    ui <- shinyUI(fluidPage(
      mainPanel(
        uiOutput("hipanel")
      )))
    
    
    server <- shinyServer(function(input, output,session){
    
      output$hipanel<- renderUI({
        bsCollapse(
          bsCollapsePanel("This panel works",helpText("OK")),
          bsCollapsePanel("hello",helpText("It's working!"))
        )
    
      })
    })
    
    
    shinyApp(ui,server)
    

    【讨论】:

    • 感谢您的回复,但我特别希望在服务器端有bsCollapsePanel,在用户界面中有bsCollapse。我需要动态生成一些面板,我不想诉诸将整个 UI 放在 renderUI 中(我的大部分 UI 都是可折叠的)。
    猜你喜欢
    • 2017-09-16
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多