2016-12-08 102 views
0

我正嘗試使用基於在主體中選擇的選項卡更新我的Shiny Dashboard側邊欄。所以當選擇標籤「Overall」時,這應該顯示條件面板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") 
    )))) 

回答

0

你的示例代碼是不好的,我想你應該看看這個飼料: 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) 

它應該做你想做的 - >反應式側邊菜單