Making tabs Dynamic/Interactive?

Hi all,

is there a way to make the tabs interactive/Dynamic. For example, in the below example, suppose if Mycars did not have any data, then "MTCARS" tabs should not be shown. Similarly for Iris as well?

library(shiny)
library(DT)
runApp(list(
  ui = pageWithSidebar(
    headerPanel('Dynamic Tabs'),
    sidebarPanel(
      numericInput("nTabs", 'No. of Tabs', 5)
    ),
    mainPanel(
       tabsetPanel(
         tabPanel(
           "IRIS",DT::dataTableOutput('iris_table')
         ),
         tabPanel(
           "MTCARS",DT::dataTableOutput('mtcars_table')
         ) 
       )
    )
  ),
  server = function(input, output, session){
  
    output$iris_table <- DT::renderDataTable(
      DT::datatable(head(iris))
    )
    
    output$mtcars_table <- DT::renderDataTable(
      DT::datatable(head(mtcars))
    )
    
  }
))

You can hide / show elements based on conditions using the shinyjs package. Have a look at the below example app:

any UI can be made dynamic with uiOutput placeholders and renderOutput server functions, or by inserting and removing UI
https://shiny.rstudio.com/articles/dynamic-ui.html

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.