Different inputs & sidebars for each tab

I want my app to load 3 tabs: Trend, Top 10, and TBD, each having their own sidebar & inputs. I can't figure out what to nest inside of what to make that happen, and the limited examples I've found aren't helping.

I think there's a way to connect an ID to each tab and have various inputs display based on which tab (& therefore ID) is selected... but i can't figure out how to do that. See my UI code below.

library(shiny)
library(shinythemes)

# Define UI for dataset viewer application
fluidPage(theme = shinytheme("simplex"),

  # Application title
  titlePanel("Baby Names Throughout Modern U.S. History, 1880 - 2016"),

  sidebarLayout(
sidebarPanel(
  conditionalPanel(
    condition = "input$id == 'tab1'",
    textInput(inputId = "list", label = "Enter a name:", value = "Jessie"),
  sliderInput(inputId = "year", label = "Select a year:", value = 2016, min = 1880, max = 2016, step = 1, sep = ""),
  submitButton("Refresh View")
)),

mainPanel(
  tabsetPanel(
    tabPanel("Trend", plotOutput("view"), id = "tab1"),
    tabPanel("Top 10 Table", plotOutput("TenTable")),
    tabPanel("TBD Tab", plotOutput("Test2"))
      )
    )
  ),
  tags$footer("Footer here.")
)

It's quite straightforward to create a multi-page app with separate sidebars on each page using the navbarPage() layout (the pages are created with the tabPanel() function). You can see an old example in the very first app I ever made here; the code is on GitHub here.

E.g. you could specify a UI using something like the below to get a multi-page app with a separate sidebar and main panel on each page.

shinyUI(navbarPage("App Title",
  tabPanel("Tab Name",
    sidebarPanel([inputs for the first tab]),
    mainPanel([outputs for the first tab])
  ),
  tabPanel("Second tab name",
    sidebarPanel([inputs for the second tab]),
    mailPanel([outputs for the second tab])
  )
))
3 Likes

Is there any way to change the aesthetics? I prefer the classic tabset look to the bootstrap bar.

Hi @bkitej, welcome to the community!

Yes, there probably is, but to dig in to that, it might be better to open up a new post to ask that question specifically, as this one was answered quite a while ago.

If you want to read about alternatives to the default bootstrap theme, you could investigate the shinythemes package as a starting point, too.