1

I have a tabsetPanel() and I try to hide one tabPanel() if choice is two and checkbox is on. I tried the following code to do that, however it does not work.

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")
      )
    )
  )

)
)

server

shinyServer(function(input,output,session){

})

How can I hide a tabPanel()?

Tonio Liebrand
  • 17,189
  • 4
  • 39
  • 59
AwaitedOne
  • 992
  • 3
  • 19
  • 42
  • hide or show if this condition: `"input.radio ==2 && input.checkbox == true"` is met. The description doesnt match the code i think :) – Tonio Liebrand Jun 08 '17 at 09:32
  • 1
    You could do something like [this](https://groups.google.com/d/msg/shiny-discuss/Coe8drGPJbU/5JXdisgVFAAJ) – SBista Jun 08 '17 at 09:49
  • :) just wanted to add that as an alternative, as sthg closer to `conditionalPanel()` is seeked. Good idea. – Tonio Liebrand Jun 08 '17 at 10:03
  • @SBista Thank you. Can I do something like `condition = input$radio && inpu$checkbox`, I mean two condition seems not working – AwaitedOne Jun 08 '17 at 11:48
  • Possible duplicate of [Add dynamic tabs in shiny dashboard using conditional panel](https://stackoverflow.com/questions/38931578/add-dynamic-tabs-in-shiny-dashboard-using-conditional-panel) – Pork Chop Jun 09 '17 at 07:11

1 Answers1

5

You could do it with renderUI(): Create the tabpanels() in a list within the renderUI() and conditionally add the third one: if(input$radio == 2 & !input$checkbox) and then return the whole tabsetPanel() with 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)
Tonio Liebrand
  • 17,189
  • 4
  • 39
  • 59
  • Isn't it possible to do with `conditionalPanel` – AwaitedOne Jun 08 '17 at 09:47
  • 2
    Well first of all, you are welcome. Concerning your question: I doubt it, because i afaik `conditionalPanel()` is a panel itself. If you read the docu `?conditionalPanel()`, the arguments are called `... = Elements to include in the panel.` So you would try to put a panel within a panel, while you just want to add a condition to a panel,...To my knowledge `renderUI()` would be the best practise here. What did your research show you, any hints it could work anyway? – Tonio Liebrand Jun 08 '17 at 09:53