Show/Hide Tabs created in tabset panel

Dear All,
In my code below, i have created tabs using tabset panel. I want to hide tab 3 and 4(not delete),
and when required I want to show them. Is there a way we can execute this. Please assist.

'''
UI

library(shiny)
library(shinydashboard)

shinyUI(fluidPage(

titlePanel("Test of Skills"),

sidebarLayout(

sidebarPanel(("Details Enter Page"),

             selectInput("data", "Select the dataset which has to be selected for analysis", 
                         
                         choices = c("iris" , "pressure" , "USArrests")),
             
             radioButtons("color", "Select the color of the histogram", 
                          choices = c("green", "orange","red","pink")),
             
             sliderInput("bins", "select the number of bins required for histogram", 
                         min = 5 , max = 25 , value = 5 , step = 1),
             
             numericInput("obs" , "Select the number of observation required for dataset" , 
                          
                          min = 5, max = 100 , value = 5 , step = 1),
             
             submitButton("Confirm")),
               
mainPanel((" Analysis Of the Dataset"),

                        tabsetPanel(type = c("pills"),
                      
                      tabPanel("Summary", h1(textOutput("MysumHeader")) ,
                               verbatimTextOutput("Mysum")),
                      
                      tabPanel("Structure and Observation" , h1(textOutput("Mystrobsheader")),
                               verbatimTextOutput("Mystr") , h1(textOutput("Myobsheader")), verbatimTextOutput("Myobs")),
                      
                      tabPanel("Data Selected" , tableOutput("Mydata")),
                      
                      tabPanel("Histogram Plot"))

))))

Server

library(shiny)
library(shinydashboard)
library(datasets)

shinyServer(function(input,output){

output$Mysum <- renderPrint({

            summary(get(input$data))

})
output$MysumHeader <- renderText({

paste("The Dataset which is selected for analysis" , input$data)

})

output$Mystr <- renderPrint({

str(get(input$data))

})

output$Mystrobsheader <- renderText({

paste("DataSet selected for structure is " , input$data)

})

output$Myobs <- renderPrint({

head(get((input$data)))

})

output$Myobsheader <- renderText({

paste("First" , input$obs , "Selected from the datase" , input$data)

})

output$Mydata <- renderTable({

View(get(input$data))

})

})
'''

You want shiny::showTab and shiny::hideTab and appropriate events to trigger these.

You also want to add a 'session' argument in your server function, as well as an 'id' argument inside of tabsetPanel.

Here is a app.R version of what I think you want, using a checkbox as the trigger. Btw, I never used a submitButton before - it threw me for a loop!

library(shiny)
library(shinydashboard)
library(datasets)

ui <- shinyUI(fluidPage(
  
  titlePanel("Test of Skills"),
  
  sidebarLayout(
    
    sidebarPanel(("Details Enter Page"),
                 checkboxInput(inputId = "hide_tab",label = "Hide 'Data Selected' tab"),
                 selectInput("data", "Select the dataset which has to be selected for analysis", 
                             
                             choices = c("iris" , "pressure" , "USArrests")),
                 
                 radioButtons("color", "Select the color of the histogram", 
                              choices = c("green", "orange","red","pink")),
                 
                 sliderInput("bins", "select the number of bins required for histogram", 
                             min = 5 , max = 25 , value = 5 , step = 1),
                 
                 numericInput("obs" , "Select the number of observation required for dataset" , 
                              
                              min = 5, max = 100 , value = 5 , step = 1),
                 
                 submitButton("Confirm")),
    
    mainPanel((" Analysis Of the Dataset"),
              
              tabsetPanel(id = "my_tabs",type = c("pills"),
                          
                          tabPanel("Summary", h1(textOutput("MysumHeader")) ,
                                   verbatimTextOutput("Mysum")),
                          
                          tabPanel("Structure and Observation" , h1(textOutput("Mystrobsheader")),
                                   verbatimTextOutput("Mystr") , h1(textOutput("Myobsheader")), verbatimTextOutput("Myobs")),
                          
                          tabPanel("Data Selected",tableOutput("Mydata")),
                          
                          tabPanel("Histogram Plot"))
    ))))

server <- shinyServer(function(input,output,session){
  observeEvent(input$hide_tab,ignoreNULL = FALSE, ignoreInit = TRUE, {
    if(isTRUE(input$hide_tab)) {
      shiny::hideTab(inputId = "my_tabs",
                     target = "Data Selected")
      shiny::hideTab(inputId = "my_tabs",
                     target = "Histogram Plot")
    } else {
      shiny::showTab(inputId = "my_tabs",
                     target = "Data Selected")
      shiny::showTab(inputId = "my_tabs",
                     target = "Histogram Plot")
    }
    
  })
  
  output$Mysum <- renderPrint({

    summary(get(input$data))
  })
  output$MysumHeader <- renderText({
    
    paste("The Dataset which is selected for analysis" , input$data)
  })
  
  output$Mystr <- renderPrint({
    
    str(get(input$data))
  })
  
  output$Mystrobsheader <- renderText({
    
    paste("DataSet selected for structure is " , input$data)
  })
  
  output$Myobs <- renderPrint({
    
    head(get((input$data)))
    
  })
  
  output$Myobsheader <- renderText({
    
    paste("First" , input$obs , "Selected from the datase" , input$data)
    
  })
  
  output$Mydata <- renderTable({
    
    View(get(input$data))
  })
  
})

shinyApp(ui,server)

Dear Sir, Thank you for your kind assistance.

Dear @michaelbgarcia can we make use of selectInput or Radiobutton and set its default value as TRUE or FALSE. Basic intention is that no changes can be made after running the app. I shall try myself and share you the update.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.