Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

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

like image 622
Iain Avatar asked Dec 15 '22 11:12

Iain


1 Answers

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

like image 141
Pork Chop Avatar answered Jan 31 '23 08:01

Pork Chop