4

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

sidebarMenu(
    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:

observeEvent(input$go,{
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

Thanks

Iain

1 Answer 1

12

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)

enter image description here

1
  • exactly, thanks. I wasn't sure on how to set the id for the sidebarMenu
    – Iain
    Oct 6, 2015 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.