Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
515 views
in Technique[技术] by (71.8m points)

r - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...