Using uiOutput in menuSubItem of shinydashboard

▼魔方 西西 提交于 2019-12-24 04:01:18

问题


When I use uiOutput in a menuSubItem, the dropdown menu that I'm trying to dynamically render does not show up. Is this not supported or am I doing something wrong? Here's a reproducible example:

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

})

回答1:


The issue got rectified by explicitly specifying the tab name of each menuSubItem as follows:

# 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"))
        )
     )
)


来源:https://stackoverflow.com/questions/33430813/using-uioutput-in-menusubitem-of-shinydashboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!