R闪亮的conditionalPanel显示两个条件

时间:2017-12-10 00:08:33

标签: r shiny conditional

我正在尝试使用多标签应用,我希望第二个标签的页面布局以第一个面板的输入为条件。基本上,如果第一个面板中的值为1,我希望第二个面板显示1组文件输入,如果用户在第一个面板中输入值2,那么我希望第二个面板显示2个文件输入。目前我的代码显示两个条件,我不确定为什么。请参阅下面的可重现代码。

ui = 
navbarPage("Page Title",
  tabPanel("Panel 1",
    sidebarPanel(
        ## Add Name,
        ## Number of surveys analysising
        numericInput("n_values", "Number of columns in next panel:", 1, min = 1, max = 2)
    ),
    mainPanel(
      tags$div(
        h2("Home Page") 
      )
    )
   ),
    tabPanel("Panel 2",
      conditionalPanel(condition = "input.n_values == 1",
        fixedPage(theme = "flatly",
          fixedRow(
            column(2,"First Column",
              fileInput("File1", "Choose a CSV files",accept = c("text/csv","text/comma-separated-values",".csv"), multiple = F),
              p("Click the button to check the data was read in correctly")
            ),
            fixedRow(
              column(12,
                verbatimTextOutput("errorText")
              )
            )    
          )
        )
      ),
      conditionalPanel(condition = "input.n_values == 2",
        fixedPage(theme = "flatly",
          fixedRow(
            column(2,"First Column",
              fileInput("File1", "Choose a CSV files",accept = c("text/csv","text/comma-separated-values",".csv"), multiple = F),
              p("Click the button to check the data was read in correctly")
            ),
            column(2,"Second Column",
              fileInput("File2", "Choose a CSV files",accept = c("text/csv","text/comma-separated-values",".csv"), multiple = F),
              p("Click the button to check the data was read in correctly")
            ),          
            fixedRow(
              column(12,
                verbatimTextOutput("errorText")
              )
            )    
          )
        )
      )      
    )  
  )

server = function(input, output,session) {
  ## Call the error message function and print
  output$errorText <- renderText({
    validate(
      need(!is.null(input$File1)
             , 'You need to input the files before we can validate the data. Please select all the necessary files.')
      )
  })
} 

shinyApp(ui, server)

1 个答案:

答案 0 :(得分:2)

那是因为你的UI中有两次verbatimTextOutput("errorText")。你不能在Shiny中做到这一点。输出必须仅包含在一个地方。