I created a dynamic cyber menu in R shinydashboard. Despite the fact that I use selected = TRUE , in this dynamic mode, the menu item associated with the menu will not be selected.
How can I make sure that I have control over what menu contents are displayed when starting in this dynamic mode?
I looked through all related topics. Could not find anything that still works. updateTabItems() does not seem to work.
Any ideas? thanks in advance.
library(shiny) library(shinydashboard) ui <- dashboardPage( dashboardHeader(title = "Dynamic sidebar"), dashboardSidebar( sidebarMenuOutput("menu") ), dashboardBody( tabItems( tabItem(tabName = "m1", p("Menu content 1") ), tabItem(tabName = "m2", p("Menu content 2") ) ) ) ) server <- function(input, output) { output$menu <- renderMenu({ sidebarMenu( menuItem("Menu item1", tabName="m1", icon = icon("calendar")), menuItem("Menu item2", tabName="m2", icon = icon("database"),selected = TRUE) ) }) } shinyApp(ui, server)
Edit: indentation issue that occurs with Romain anwser 
source share