隐藏闪亮的任何tabpanel

时间:2017-06-08 09:18:34

标签: r shiny

我有import { Employee } from '/imports/api/employee/employee.js'; Template.employee.helpers({ employee_list: function() { var emp = Employee.find().fetch(); console.log('emp', emp); }); ,如果选项为2且tabsetPanel()已启用,我会尝试隐藏一个tabPanel()。我尝试了以下代码来执行此操作,但它不起作用。

UI

checkbox

服务器

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){ })

1 个答案:

答案 0 :(得分:4)

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

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)