【问题标题】:Shiny ConditionalPanel for Sidebar侧边栏的闪亮条件面板
【发布时间】:2017-04-23 05:27:42
【问题描述】:

我正在尝试根据在主体中选择的选项卡更新我的 Shiny Dashboard Sidebar。 So when tab "Overall" is selected then this should display the menu items in Conditional Panel 1 (TA.Name1,TA.Name2), and when tab "Other" is selected then the sidebar displays the menu items for conditional panel 2. Data如下:

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    conditionalPanel(condition="input.conditionedPanels==1", sidebarMenu(width=150,
      menuItem("TA.Name1", tabName = "TA1")),
      menuItem("TA.Name2", tabName = "TA2"))),
    conditionalPanel(condition="input.conditionedPanels==2",sidebarMenu(width=150,
      menuItem("EA.Name1", tabName = "EA1")),
      menuItem("EA.Name2", tabName = "EA2"))),             
  dashboardBody(
     tabsetPanel(
        tabPanel("Overall",value=1,fluidRow(
          column(3,selectInput("PACO", h5("PACO"), levels(OA$PACO)))),
          tabItems(
            tabItem(tabName = "TA1","TA1"),fluidRow(
               box(title="TA.Name1,dygraphOutput("TA1.data")),
               box(title="TA.Name2,dygraphOutput("TA2.data")))),
            tabItem(tabName = "TA2","TA2")
    )),
        tabPanel("Other",value=2,fluidRow(
          column(3,selectInput("CV", h5("CV"), levels(OA$CV)))),
          tabItems(
            tabItem(tabName = "EA1","EA1"),fluidRow(
               box(title="EA.Name1,dygraphOutput("EA1.data")),
               box(title="EA.Name2,dygraphOutput("EA2.data")))),
            tabItem(tabName = "EA2","EA2")
    ))))

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您的示例代码不好,我认为您应该看看这个提要: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

    我必须简化您的代码才能真正找到解决方案...

    看看吧:

    library(shiny)
    library(shinydashboard)
    
    ui <- dashboardPage(
      dashboardHeader(),
      dashboardSidebar(
          sidebarMenu(id="tabs",
                      sidebarMenuOutput("menu"))),
      dashboardBody(
      tabsetPanel(id="tabs2",
      tabPanel("Overall",value=1),
      tabPanel("Other",value=2))))
    
    server <-  function(input, output, session) {
    
      output$menu <- renderMenu({
        if (input$tabs2 == 1 ) {
        sidebarMenu(
          menuItem("TA.Name1", tabName = "TA1"),
          menuItem("TA.Name2", tabName = "TA2"))}
        else{
          sidebarMenu(
            menuItem("EA.Name1", tabName = "EA1"),
            menuItem("EA.Name2", tabName = "EA2"))
        }
      })
      }
    
    shinyApp(ui = ui, server = server)
    

    它应该做你想做的 --> 反应式侧边栏菜单

    【讨论】:

      猜你喜欢
      • 2016-02-26
      • 1970-01-01
      • 2015-10-27
      • 2021-01-29
      • 1970-01-01
      • 2018-06-02
      • 2019-12-21
      • 1970-01-01
      • 2013-11-03
      相关资源
      最近更新 更多