简体   繁体   English

侧边栏的闪亮ConditionalPanel

[英]Shiny ConditionalPanel for Sidebar

I am trying to use update my Shiny Dashboard Sidebar based on the tab selected in the Main body. 我正在尝试根据主体中选择的选项卡更新我的Shiny Dashboard侧栏。 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 is bellow: 因此,当选择选项卡“总体”时,这将在条件面板1中显示菜单项(TA.Name1,TA.Name2),并且当选择选项卡“其他”时,边栏将显示条件面板2的菜单项。吼叫:

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

Your Example Code is not good, i think You should have a look at this feed: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example 您的示例代码不好,我认为您应该看一下此提要: http : //stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

I had to simplify Your code to actually find solution... 我必须简化您的代码才能真正找到解决方案...

Have a look at it: 看看它:

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)

It should do what You want -- > reactive sidebarMenu 它应该做你想要的->反应性sidebarMenu

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM