2016-07-11 53 views
0

我使用conditionalPanel創建第一呈現的選項給用戶的面板的UI,然後顯示使用tabsetPanel選項卡式儀表板。如下所示添加另一個tabPabel的簡單行爲會以某種方式阻止server.R文件運行。我測試過使用打印語句。這看起來像Shiny應用程序正在打破,但我找不到語法錯誤或任何理由。ř閃亮conditionalPanel奇數行爲

conditionalPanel(
    condition = "output.panel == 'view.data'", 
    tabsetPanel(id = "type", 
    tabPanel("Script", value = "script", 
     fluidPage(
     br(), 
     fluidRow(
      column(3, uiOutput("script.name")), 
      column(3, uiOutput("script.message")) 
     ), 
     hr(), 
     plotlyOutput("plotly") 
    ) 
    ), 
    tabPanel("Location", value = "location", 
     fluidPage(
     br(), 
     fluidRow(
      # column(3, uiOutput("id.range")) 
     ), 
     hr(), 
     plotlyOutput("plot") 
    ) 
    ) 
    # when this tabPanel is uncommented it doesn't work 
    # ,tabPanel("Accelerometer", value = "accelerometer", 
    # fluidPage(
    #  br(), 
    #  hr(), 
    #  plotlyOutput("plot") 
    # ) 
    #), 
) 
) 

回答

0

這不是失敗,因爲附加tabPanel,它的失敗,因爲它包含重複引用output$plotserver功能的每個輸出只能顯示一次。例如,該運行,但如果重複的行註釋掉會失敗:

library(shiny) 

ui <- shinyUI(fluidPage(
    # textOutput('some_text'), 
    textOutput('some_text') 
)) 

server <- shinyServer(function(input, output){ 
    output$some_text <- renderText('hello world!') 
}) 

runApp(shinyApp(ui, server)) 

一個簡單的解決方案是將render*功能的結果保存到一個局部變量,然後你就可以保存到兩個輸出:

library(shiny) 

ui <- shinyUI(fluidPage(
    textOutput('some_text'), 
    textOutput('some_text2') 
)) 

server <- shinyServer(function(input, output){ 
    the_text <- renderText('hello world!') 
    output$some_text <- the_text 
    output$some_text2 <- the_text 
}) 

runApp(shinyApp(ui, server)) 
+0

謝謝!這是問題所在。 – asmalluser