我在使用 Shiny dashboardSidebar 时遇到了麻烦
I have troubles with Shiny dashboardSidebar
我像这样创建了闪亮的仪表板侧边栏
我通过 tabName
将 MenuItem
链接到 tabItem
,并在每个 tabItem 中放入 tabsetPanel
我希望,当我选择组 A 时,能够显示子组 A1、A2 和 A3 的不同面板。我想对 B 组及其子组做同样的事情。我做不到,因为只显示了 B 组中的面板。我想保留此 dashboardSidebar 架构。
下面是我的脚本
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)
由于您在第一个 sidebarmenu
项目中使用多个 selectInput
s(子项目),因此您需要在该项目下使用 menuSubItem
(或 menuItem
)使用 tabName
。这里tabNamegpA1
就是你需要在dashboardBody
中引用的。当您有子项目时,您无法使用 gpA
访问选项卡面板。试试这个
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)
我像这样创建了闪亮的仪表板侧边栏
我通过 tabName
将 MenuItem
链接到 tabItem
,并在每个 tabItem 中放入 tabsetPanel
我希望,当我选择组 A 时,能够显示子组 A1、A2 和 A3 的不同面板。我想对 B 组及其子组做同样的事情。我做不到,因为只显示了 B 组中的面板。我想保留此 dashboardSidebar 架构。
下面是我的脚本
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)
由于您在第一个 sidebarmenu
项目中使用多个 selectInput
s(子项目),因此您需要在该项目下使用 menuSubItem
(或 menuItem
)使用 tabName
。这里tabNamegpA1
就是你需要在dashboardBody
中引用的。当您有子项目时,您无法使用 gpA
访问选项卡面板。试试这个
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)