2017-06-08 87 views
0

我有一个tabsetPanel(),我试图隐藏一个tabPanel()如果选择是两个,checkbox打开。我尝试了下面的代码来做到这一点,但它不起作用。隐藏闪亮的任何tabpanel

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(
     tabsetPanel(
     tabPanel("Plot", "plot1"), 
     conditionalPanel(
      condition = "input.radio !=2 && input.checkbox == false", 
     tabPanel("Summary", "summary1") 
     ), 
     tabPanel("Table", "table1") 
    ) 
    ) 
) 

) 
) 

服务器

shinyServer(function(input,output,session){ 

}) 

我怎么能隐藏tabPanel()

+0

隐藏或显示是否满足以下条件:''input.radio == 2 && input.checkbox == true“'。该描述不符合我认为的代码:) – BigDataScientist

+1

你可以做一些像[this](https://groups.google.com/d/msg/shiny-discuss/Coe8drGPJbU/5JXdisgVFAAJ) – SBista

+0

:)只是想补充一点作为另一种选择,因为sthg更接近'conditionalPanel()'。好主意。 – BigDataScientist

回答

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) 
+0

是不是可以使用'conditionalPanel' – AwaitedOne

+0

首先,欢迎您。关于你的问题:我怀疑它,因为我afaik'conditionalPanel()'是一个面板本身。如果你阅读了文档'?conditionalPanel()',参数被称为'... = \t 要包含在面板中的元素。“所以你会尝试在面板中放置一个面板,而你只是想添加一个条件到一个面板,......据我所知,'renderUI()'将是这里的最佳实践。你的研究向你展示了什么,无论如何,它的任何提示都可以起作用? – BigDataScientist