I have a shinydashboard with tabItems and sub-items.Every one them when selected should display the the respective Item in the main body but this does not work.
#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) { }
There are several changes you need to make:
menuSubItem
instead of menuItem
for tab retAA
retAA
and selectInput
should be siblings 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.