Iain Iain - 5 months ago 26
R Question

Navigate to particular sidebar menu item in ShinyDashboard?

(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 ShinyDashboard?

menuItem("Menu Item 1")
menuItem("Menu Item 2")

i.e. how can I put a button on the "Menu Item 1" page that will link to "Menu Item 2"?

To navigate between tabs I am using the updateTabsetPanel function:

updateTabsetPanel(session, "tabset1", selected = "Step 2")

I believe I should be able to use a similar function to navigate to a sidebar menu, but I am not sure what that is.

Any pointers greatly appreciated



Answer Source

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


ui <- dashboardPage(
  dashboardHeader(title = "Simple tabs"),
    sidebarMenu(id = "tabs",
      menuItem("Menu Item 1", tabName = "one", icon = icon("dashboard")),
      menuItem("Menu Item 1", tabName = "two", icon = icon("th"))
      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)

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download