Are tabs with their own sidebars and mainPanels possible in shiny?

shiny multiple sidebar panels
shiny dashboard tabs
r shiny multiple tabs
shiny navbarpage
r shiny no sidebar
shiny sidebar panel on top
r shiny multiple pages
wellpanel shiny

I would like to display different inputs for different tabs. So I tried to build a page with several tabPanels. However, I can't have sth like below:

library(shiny)

shinyUI(pageWithSidebar(
  headerPanel("Header"),

  tabsetPanel(
    tabPanel(
      headerPanel("Tab 1"),
      sidebarPanel(
        selectInput("var", "Parametre", choices = c("1", "2", "3"))
        ),
      mainPanel(
        textOutput("text1")
        )
      ),
    tabPanel(
      headerPanel("Tab 2"),
      sidebarPanel(
        selectInput("var", "Parametre", choices = c("21", "22", "23"))
      ),
      mainPanel(
        textOutput("text2")
      )
    )
    )
  ))

I suspect that the pageWithSidebar is causing the problem, but I couldn't find an alternative in google groups. Is there a way to display several tabs with their own sidebars and mainPanels, or shall I create different apps for this purpose?


If I do not misunderstand your question, I think you can even evade the jQuery part (from @f1r3br4nd answer) by supplying an id for the tabsetPanel function, here id = "conditionedPanels". The value parameter (i.e. which tab is selected in the main panel) is then available via the input variable.

A minmal example: server.R may be empty except for the shinyServer function skeleton. The ui.R file might be as follows.

shinyUI(pageWithSidebar(
  headerPanel("Conditional Panels"),
  sidebarPanel(
    conditionalPanel(condition="input.conditionedPanels==1",
                     helpText("Content Panel 1")
    ),
    conditionalPanel(condition="input.conditionedPanels==2",
                     helpText("Content Panel 2")
    ) 
  ),
  mainPanel(
    tabsetPanel(
      tabPanel("Panel 1", value=1), 
      tabPanel("Panel 2", value=2)
      , id = "conditionedPanels"
    )
  )
))

Are tabs with their own sidebars and mainPanels possible in shiny?, If I do not misunderstand your question, I think you can even evade the jQuery part (from @f1r3br4nd answer) by supplying an id for the tabsetPanel function,  1.r - Are tabs with their own sidebars and mainPanels possible in shiny? 2.r - Hide an element (box/tabs) in shiny dashbaord; 3.R Shiny: conditionalPanel not working if used in different tabs; 4.r - Shiny's tabsetPanel not displaying plots in multiple tabs; 5.css - Background color of tabs in shiny tabPanel


I got mine to work by having only one sidebarPanel like in the Shiny example apps but then wrapping stuff in the sidebarPanel that's only for specific tabs in separate conditionalPanel calls as here. The trick is then to make the character string that is conditionalPanel's condition argument be a jQuery statement that looks at the html attribute of the currently selected tab and ===s it to the name of the tab for which this content should appear in the sidebar:

conditionalPanel(
    "$('li.active a').first().html()==='Foo'",
    actionButton("bar","Bar"));

...where Foo is the title of the tab.

In short, one sidebar but its content conditional on active tab.

Different inputs & sidebars for each tab - shiny, I want my app to load 3 tabs: Trend, Top 10, and TBD, each having their own sidebar library(shiny) library(shinythemes) # Define UI for dataset viewer sidebarPanel([inputs for the first tab]), mainPanel([outputs for the first  Are tabs with their own sidebars and mainPanels possible in shiny? tabs with their own sidebars and mainPanels, or shall I create different apps for this purpose


I know this is an old post but I stumbled across it when I was looking for an answer to a similar question. I think you can also accomplish what you want by using a fluidPage (instead of pageWithSidebar) and then using the sidebarLayout function in each of the tabPanels.

An example:

library(shiny)

ui <- fluidPage(
  headerPanel("Header"),
  tabsetPanel(
    tabPanel('Tab 1',
             sidebarLayout(
               sidebarPanel(
                 selectInput("var", "Parametre", choices = c("1", "2", "3"))
               ),
               mainPanel(
                 textOutput("text1")
               )
             )  
    ),
    tabPanel('Tab 2',
             sidebarLayout(
               sidebarPanel(
                 selectInput("var", "Parametre", choices = c("21", "22", "23"))
               ),
               mainPanel(
                 textOutput("text2")
               )
             )
    )
  )
)

server <- function(input, output) {}

shinyApp(ui, server)

Tabsets, The Tabsets application demonstrates using tabs to organize output. definitions ---- sidebarLayout( # Sidebar panel for inputs ---- sidebarPanel( # Input: Main panel for displaying outputs ---- mainPanel( # Output: Tabset w/ plot​, summary, In this example each tab provides its own view of the dataset. Tab Panels. Tabsets are created by calling the tabsetPanel function with a list of tabs created by the tabPanel function. Each tab panel is provided a list of output elements which are rendered vertically within the tab. In this example we added a summary and table view of the data to the Hello Shiny app, each rendered on their own tab.


Mastering RStudio – Develop, Communicate, and Collaborate with R, Instead, you can display each output in its own tab, while the sidebar does not change. tabsetPanel() function was assigned as follows: mainPanel( tabsetPanel(position = "below", tabPanel("Plot", [140 ] Shiny – a Web-app Framework for R. I am trying to build a shiny app where the sidebar is dynamic based on the tab that is selected. The sidebar is populated by a csv file. Right now it is just reading a CSV file named machines.csv. I would want that to be able to read for example austin.csv, dallas.cav based on the tab name. There will be 7 tabs total.


Shiny Web Apps, tabsetPanel allows multiple tabPanel elements within a mainPanel (sharing the sidebars for each tab; see here for more info about Shiny layout options, Run as much code as possible server function / render function run once run per there is a runGitHub function that allows apps to be run directly from github, but I'​m  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


Application layout guide, The simple default layout with a sidebar for inputs and a large main sidebarLayout(position = "right", sidebarPanel( # Inputs excluded for brevity ), mainPanel( # Outputs It's also possible to offset the position of columns to achieve more (each with their own sidebar, tabsets, or other layout constructs). You may want to create a Shiny application that consists of multiple distinct sub-components (each with their own sidebar, tabsets, or other layout constructs). The navbarPage() function creates an application with a standard Bootstrap Navbar at the top. For example: