2

当我uiOutput在 amenuSubItem中使用时,我尝试动态呈现的下拉菜单不会显示。这是不支持还是我做错了什么?这是一个可重现的示例:

### 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_)
    })

})
4

1 回答 1

3

通过明确指定每个选项卡的名称,该问题得到纠正,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"))
        )
     )
)
于 2015-11-19T09:20:30.600 回答