2016-12-15 68 views
0

我有一個儀表板,應該可以幫助用戶跟蹤雜事列表。這些雜事在sidebarMenu中列爲menuSubItem。因此,如果創建了與雜項相對應的文件,我想要在menuSubItem旁邊放置一個支票圖標。動態菜單:帶有子項目的ID項

我有一個很難理解爲什麼那些menuSubItem拭目以待,直到我點擊了test,然後再home被渲染。我試圖打印出input$test_subitems,似乎我無法跟蹤時test被選中。

library(shiny) 
library(shinydashboard) 

ui <- dashboardPage(
    skin = "blue", 

    dashboardHeader(title = "Dynamic Menu"), 
    dashboardSidebar(
    sidebarMenu(
     id = "sidebarMenu", 
     menuItem("Home", tabName = "home", icon = icon("home")), 
     menuItem("Item with subitems", tabName = "test", 
       uiOutput("test_subitems")) 
    ) 
), 

    dashboardBody(id = "dashboardBody") 
) 

server <- shinyServer(function(input, output, session) { 
    observe(cat('1:', input$sidebarMenu, '\n')) 

    output$test_subitems <- renderUI({ 
    print(input$sidebarMenu) 
    tabs <- c("st1","st2") 
    lapply(tabs, function(tab) { 
     menuSubItem(icon = NULL, paste('Test:', tab), tabName = tab) 
    }) 
    }) 

    session$onSessionEnded(stopApp) 
}) 

shinyApp(ui, server) 

回答

0

Althought我沒有找到一個方法來與ID子項的項目,似乎suspendWhenHidden確實爲我的伎倆:

outputOptions(output, "test_subitems", suspendWhenHidden = FALSE)