0

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.

  • Using div(class= "tab-content", ui_list) instead of do.call(tagList, ui_list) seems to help the situation, however I still visualize the menuitem1 content above the proper subtab content – Butchkachu Jun 07 '23 at 08:32

0 Answers0