2015-10-30 46 views
1

當我在menuSubItem中使用uiOutput時,我試圖動態呈現的下拉菜單不顯示。這是不支持,或者我做錯了什麼?這裏有一個重複的例子:在shinydashboard的menuSubItem中使用uiOutput

### ui.R 

library(shiny) 
library(shinydashboard) 

# Create dashboard header 
header <- dashboardHeader() 

# Create dashboard sidebar 
sidebar <- dashboardSidebar(
    sidebarMenu(
     menuItem(text="test1", tabName="test1", 
       menuSubItem(icon=NULL, selectInput("x", "X", c("a", "b", "c"), selected="a")), 
       menuSubItem(icon=NULL, uiOutput("y")) 
     ) 
    ) 
) 

# Create dashboard body 
body <- dashboardBody() 

shinyUI(
    dashboardPage(
     skin="purple", 
     header, 
     sidebar, 
     body 
    ) 
) 

'

### server.R 

library(shiny) 

shinyServer(function(input, output, session) { 
    output$y <- renderUI({ 
     y_ <- switch(input$x, 
       a=1:10, 
       b=11:20, 
       c=21:30) 

     selectInput("y", "Y", y_) 
    }) 

}) 

回答

2

問題得到了明確指定每個menuSubItem的標籤名稱如下修正:

# Create dashboard sidebar 
sidebar <- dashboardSidebar(
    sidebarMenu(
     menuItem(text="test1", tabName="test1", 
       menuSubItem(icon=NULL, tabName="test1", selectInput("x", "X", c("a", "b", "c"), selected="a")), 
       menuSubItem(icon=NULL, tabName="test1", uiOutput("y")) 
     ) 
    ) 
) 
相關問題