Navigate to particular sidebar menu item in ShinyDashboard?

浪子不回头ぞ 提交于 2019-11-26 20:47:15

问题


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


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)



来源:https://stackoverflow.com/questions/32971921/navigate-to-particular-sidebar-menu-item-in-shinydashboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!