Shiny Dashboard: Menu Item: homepage + drop down menu REVISITED

Have been struggling with the very same issue posted here for a while. It was not solved and the stackoverflow links is broken.

Links to Stackoverflow are broken. Is this even possible in Shiny? Basically clicking on a MenuItem that has selectInput items and be able to link it via tabName to a tabItem. So far I'm only able to get it to work for MenuItems that do not have sub-elements.

Any ideas?

You can at least make it go to the first submenuitem of the clicked menuitem

library(shiny)
library(shinydashboard)

# Define UI for application
ui <- dashboardPage(
  dashboardHeader(title = "Shiny Dashboard"),

  dashboardSidebar(
    sidebarMenu(
      id = "mytabitems",
      menuItem("Menu Item 1", tabName = "menu_1"),
      menuItem("Menu Item 2",
        tabName = "menu_2",
        menuSubItem("Sub Menu Item 1", tabName = "sub_1"),
        menuSubItem("Sub Menu Item 2", tabName = "sub_2")
      )
    )
  ),

  dashboardBody(
    tabItems(
      tabItem(
        tabName = "menu_1",
        fluidRow(
          h1("Homepage 1")
        )
      ),
      tabItem(
        tabName = "menu_2",
        fluidRow(
          h1("Homepage 2")
        )
      ),
      tabItem(
        tabName = "sub_1",
        fluidRow(
          h1("Sub Menu Page 1")
        )
      ),
      tabItem(
        tabName = "sub_2",
        fluidRow(
          h1("Sub Menu Page 2")
        )
      )
    )
  )
)

# Define server logic
server <- function(input, output, session) {
  observe({
    cat("input$mytabitems ", input$mytabitems, "\n")
    cat("input$menu_1 ", input$menu_1, "\n")
    cat("input$menu_2 ", input$menu_2, "\n")
    cat("input$sub_1 ", input$sub_1, "\n")
    cat("input$sub_2 ", input$sub_2, "\n")
  })
  observeEvent(input$sidebarItemExpanded, {
    if (input$sidebarItemExpanded == "MenuItem2") {
      print("updating tab items")
      updateTabItems(session, "mytabitems", "sub_1")
    }
  })
}
# Run the application
shinyApp(ui = ui, server = server)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.