How do I render the actual content of a menuSubItem once selected in the Sidebar? (Shinydashboard)

24 Views Asked by At

Here is my code


library(shiny)
library(shinydashboard)

ui <- dashboardPage(
   dashboardHeader(title = "LiqTIT - beta"),
   dashboardSidebar(
      sidebarMenu(
         menuItem("menuitem 1", tabName = "menuitem1", icon = icon("database")),
         menuItemOutput("test")
      )
   ),
   dashboardBody(
      tabItems(
         tabItem("menuitem1",
                 actionButton("check", "PRIMA PREMI QUA"),
                 actionButton("start", "POI PREMI QUA")
         ),
         uiOutput("dynamicpage")
      )
   )
)

server <- function(input, output, session) {
   observeEvent(input$start, {
                req(input$check)
                output$test <- renderMenu({
                   menuItem("test",
                            lapply(c(1:5), function(x) {
                               menuSubItem(paste("Sub-item ", x), tabName = paste0("subitem",x))
                            })
                   )
                })
   })
   
   
   output$dynamicpage <- renderUI({
      ui_list <- lapply(c(1:5), function(x) {
         tabItem(paste0("subitem",x),
                 paste("sub-item ", x)
         )
      })
      do.call(tagList, ui_list)
   })
}

shinyApp(ui = ui, server = server)

The problem is that the dynamicpage content is listed from the beginning in tab menuitem 1, instead of being distributed properly in each corresponding subtab

The actual code is much more complicated, as the name of the side menu will be taken from an excel file. I tried to simplify the problem to this version but I cannot proceed further.

0

There are 0 best solutions below