2015-10-06 96 views
1

(閃亮谷歌羣組的交叉帖子,https://groups.google.com/forum/#!topic/shiny-discuss/CvoABQQoZeE導航到ShinyDashboard中特定的側邊欄菜單項?

如何導航到ShinyDashboard中的特定邊欄菜單項?

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

即如何在「Menu Item 1」頁面上放置一個按鈕,該按鈕將鏈接到「Menu Item 2」?

爲製表我用updateTabsetPanel功能的導航:

observeEvent(input$go,{ 
updateTabsetPanel(session, "tabset1", selected = "Step 2") 
}) 

我相信我應該能夠使用類似的功能導航至工具欄菜單,但我不知道那是什麼。

任何指針十分讚賞

感謝

伊恩

回答

5

這是你在找什麼?注意,例如從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

+0

採取準確,謝謝。我不確定如何爲sidebarMenu設置ID – Iain