【问题标题】:Hide any tabpanel in shiny在闪亮中隐藏任何标签面板
【发布时间】:2017-06-11 23:27:07
【问题描述】:

我有一个tabsetPanel(),如果选择是两个并且checkbox 处于打开状态,我会尝试隐藏一个tabPanel()。我尝试了以下代码来执行此操作,但是它不起作用。

用户界面

shinyUI(
  fluidPage(
    titlePanel("Hello Shiny!"),
  sidebarLayout(
    sidebarPanel(
      fluidRow(
        column(5,
               radioButtons("radio", label = h5("Data uploaded"),
                            choices = list("Aff" = 1, "Cod" = 2,
                                           "Ill" = 3),selected = 1)
        )),
      checkboxInput("checkbox", "cheb", value = F)
  ),
    mainPanel(
      tabsetPanel(
        tabPanel("Plot", "plot1"),
        conditionalPanel(
          condition = "input.radio !=2 && input.checkbox == false",
        tabPanel("Summary", "summary1")
        ),
        tabPanel("Table", "table1")
      )
    )
  )

)
)

服务器

shinyServer(function(input,output,session){

})

如何隐藏tabPanel()

【问题讨论】:

  • 隐藏或显示是否满足此条件:"input.radio ==2 && input.checkbox == true"。描述与我认为的代码不符:)
  • 你可以做类似this
  • :) 只是想添加它作为替代方案,因为正在寻找更接近conditionalPanel() 的东西。好主意。
  • @SBista 谢谢。我可以做类似condition = input$radio && inpu$checkbox 的事情吗,我的意思是两个条件似乎不起作用

标签: r shiny


【解决方案1】:

您可以使用renderUI() 做到这一点: 在renderUI() 内的列表中创建tabpanels() 并有条件地添加第三个: if(input$radio == 2 & !input$checkbox) 然后用do.call(tabsetPanel, panels)返回整个tabsetPanel()

ui <- shinyUI(
  fluidPage(
    titlePanel("Hello Shiny!"),
    sidebarLayout(
      sidebarPanel(
        fluidRow(
          column(5,
                 radioButtons("radio", label = h5("Data uploaded"),
                              choices = list("Aff" = 1, "Cod" = 2,
                                             "Ill" = 3),selected = 1)
          )),
        checkboxInput("checkbox", "cheb", value = F)
      ),
      mainPanel(
          uiOutput("summary")
        )
      )
  )
)

server <- shinyServer(function(input,output,session){

  output$summary <- renderUI({
      panels <- list(
        tabPanel("Plot", "plot1"),
        tabPanel("Table", "table1")        
      )
      if(input$radio == 2 & !input$checkbox) panels[[3]] <- tabPanel("Summary", "summary1")
      do.call(tabsetPanel, panels)
  })

})

shinyApp(ui, server)

【讨论】:

  • 不可以用conditionalPanel
  • 首先,不客气。关于您的问题:我对此表示怀疑,因为我 afaik conditionalPanel() 本身就是一个小组。如果您阅读文档?conditionalPanel(),则参数称为... = Elements to include in the panel.,因此您会尝试将面板放在面板中,而您只想向面板添加条件,...据我所知renderUI() 会成为这里的最佳实践。您的研究向您展示了什么,有什么提示可以奏效吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-10
  • 2018-08-05
  • 2017-11-26
  • 2022-06-21
  • 1970-01-01
  • 2020-07-27
  • 2019-08-19
相关资源
最近更新 更多