Navigate to particular sidebar menu item in ShinyDashboard?

前端 未结 1 1937
不思量自难忘°
不思量自难忘° 2020-12-05 22:10

(cross post from shiny google groups, https://groups.google.com/forum/#!topic/shiny-discuss/CvoABQQoZeE)

How can one navigate to a particular sidebar menu item in Sh

相关标签:
1条回答
  • 2020-12-05 22:45

    Is this what you are looking for? note that the example is taken from Change the selected tab on the client

    library(shiny)
    library(shinydashboard)
    
    ui <- dashboardPage(
      dashboardHeader(title = "Simple tabs"),
      dashboardSidebar(
        sidebarMenu(id = "tabs",
          menuItem("Menu Item 1", tabName = "one", icon = icon("dashboard")),
          menuItem("Menu Item 1", tabName = "two", icon = icon("th"))
        )
      ),
      dashboardBody(
        tabItems(
          tabItem(tabName = "one",h2("Dashboard tab content"),actionButton('switchtab', 'Switch tab')),
          tabItem(tabName = "two",h2("Widgets tab content"))
        )
      )
    )
    
    server <- function(input, output, session) {
      observeEvent(input$switchtab, {
        newtab <- switch(input$tabs, "one" = "two","two" = "one")
        updateTabItems(session, "tabs", newtab)
      })
    }
    
    shinyApp(ui, server)
    

    0 讨论(0)
提交回复
热议问题