I created my shiny dashboard sidebar like this
I linked MenuItem
to tabItem
, by tabName
and in each tabItem I put tabsetPanel
I would like, when I choose group A, to be able to display the different panels that are the subgroups A1, A2, and A3. I would like to do the same for group B and its subgroups. I can't do it, because only the panels in group B are displayed. I would like to keep this dashboardSidebar architecture.
Here are below my scripts
ui <- dashboardPage(
dashboardHeader(title = "DASHBOARD"),
dashboardSidebar(width = 250,
sidebarMenu(
menuItem( "Group A",tabName = "gpA",
selectInput(inputId = "Var1",label="variable 1", choices = c("Total","cat1","cat2"),
selected="Total"),
selectInput(inputId = "Var2",label="variable 2", choices = c("Total","cat1","cat2"),
selected="Total")),
menuItem("Group B",tabName = "gpB")
)
),
dashboardBody(
tabItems(
tabItem(
tabName = "gpA",
fluidRow(box(selectInput(inputId = "Hospital1",choices = c(LETTERS),
label = "Choice hospital 1"),
width = 6,height = 70,
solidHeader = TRUE),
box(selectInput(inputId = "Hopital2",choices = rev(c(LETTERS)),
label = "Choice hospital 2"),
width = 6,height = 70,
solidHeader = TRUE)),
fluidRow( tabsetPanel(
tabPanel("Sub group A2",
box(leafletOutput("")),box(leafletOutput(""))
),
tabPanel("Sub group A3", box(leafletOutput("")),
box(leafletOutput(""))),
tabPanel("Concurrence", leafletOutput(""))
))
),
tabItem(
tabName = "gpB",
fluidRow(box(selectInput(inputId = "Commune",choices = c(letters),
label = "choice a Zip code"),
width = 6,height = 70,
solidHeader = TRUE)),
fluidRow( tabsetPanel(
tabPanel("Sub group B1",
leafletOutput("")
),
tabPanel("Sub group B2",
leafletOutput(""))
))
)
)
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
As you are using multiple selectInput
s (sub items) within the first sidebarmenu
item, you need to use menuSubItem
(or menuItem
) under that to use the tabName
. Here tabName gpA1
is what you need to refer to in dashboardBody
. You cannot access the tabpanels with gpA
when you have sub-items. Try this
ui <- dashboardPage(
dashboardHeader(title = "DASHBOARD"),
dashboardSidebar(width = 250,
sidebarMenu( id="tabs",
menuItem( "Group A", tabName = "gpA",
selectInput(inputId = "Var1",label="variable 1", choices = c("Total","cat1","cat2"),
selected="Total"),
selectInput(inputId = "Var2",label="variable 2", choices = c("Total","cat1","cat2"),
selected="Total"),
menuSubItem("My Group A", tabName="gpA1", ### <---- refer to this tabName in dashboardBody
icon = icon("line-chart"))
),
menuItem("Group B",tabName = "gpB")
)
),
dashboardBody(
tabItems(
tabItem(
tabName = "gpA1",
fluidRow(box(selectInput(inputId = "Hospital1",choices = c(LETTERS),
label = "Choice hospital 1"),
width = 6,height = 70,
solidHeader = TRUE),
box(selectInput(inputId = "Hopital2",choices = rev(c(LETTERS)),
label = "Choice hospital 2"),
width = 6,height = 70,
solidHeader = TRUE)),
fluidRow( tabsetPanel(
tabPanel("Sub group A2",
box(leafletOutput("")),box(leafletOutput(""))
),
tabPanel("Sub group A3", box(leafletOutput("")),
box(leafletOutput(""))),
tabPanel("Concurrence", leafletOutput(""))
))
),
tabItem(
tabName = "gpB",
fluidRow(box(selectInput(inputId = "Commune",choices = c(letters),
label = "choice a Zip code"),
width = 6,height = 70,
solidHeader = TRUE)),
fluidRow( tabsetPanel(
tabPanel("Sub group B1",
leafletOutput("")
),
tabPanel("Sub group B2",
leafletOutput(""))
))
)
)
)
)
server <- function(input, output) {
}
shinyApp(ui, server)