我有一个带有tabItems和子项目的闪亮仪表板,选中它们时每个都应在主体中显示相应的项目,但这不起作用。
#ui.r
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
ui <- dashboardPagePlus(
dashboardHeaderPlus(title = "AA Tester"),
dashboardSidebar(
dashboardSidebar(
sidebarMenu(id = 'sidebarmenu',
menuItem('Introduction', tabName = 'intro', icon = icon('dashboard')),
menuItem('Explore Funds', tabName = 'expf',
icon = icon('th'),
menuItem('Choose Strategy',
tabName = 'retAA',
icon = icon('line-chart'),
selectInput("str", "Strategies:", choices=c("Strategy 1",
"Strategy 2",
"Strategy 3",
"Strategy 4",
"Strategy 5",
"Strategy 6",
"Strategy 7",
"Strategy 8"),multiple = T,selected = "Strategy 1"))
)))
),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "intro",
fluidRow(
h2("Intro tab content")
)
),
# Second tab content
tabItem(tabName = "retAA",
h2("Exp tab content")
)
)
)
)
#server.r
server <- function(input, output) { }
答案 0 :(得分:1)
您需要进行一些更改:
menuSubItem
中使用menuItem
代替retAA
retAA
和selectInput
应该是兄弟姐妹selectInput
#ui.r
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
ui <- dashboardPagePlus(
dashboardHeaderPlus(title = "AA Tester"),
dashboardSidebar(
dashboardSidebar(
sidebarMenu(id = 'sidebarmenu',
menuItem('Introduction', tabName = 'intro', icon = icon('dashboard')),
menuItem('Explore Funds', tabName = 'expf',
icon = icon('th'),
menuSubItem('Choose Strategy',
tabName = 'retAA',
icon = icon('line-chart')), # point 1
selectInput("str", "Strategies:", choices=c("Strategy 1",
"Strategy 2",
"Strategy 3",
"Strategy 4",
"Strategy 5",
"Strategy 6",
"Strategy 7",
"Strategy 8"),multiple = T,selected = "Strategy 1") # point 2
)))
),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "intro",
fluidRow(
h2("Intro tab content")
)
),
# Second tab content
tabItem(tabName = "retAA",
h2("Exp tab content"),
textOutput("userStr") # point 3
)
)
)
)
#server.r
server <- function(input, output) {
output$userStr <- renderText(input$str) # point 4
}
shiny::shinyApp(ui,server)