【问题标题】:R shiny conditionalPanel displaying both conditionsR闪亮的条件面板显示两种条件
【发布时间】:2017-12-10 00:08:32
【问题描述】:

我正在尝试使用多选项卡应用程序,我希望第二个选项卡的页面布局以第一个面板的输入为条件。基本上,如果第一个面板中的值为 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)

【问题讨论】:

    标签: r shiny conditional


    【解决方案1】:

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

    【讨论】:

    • 谢谢你,我怎样才能有条件的页面部分和条件之间共有的部分页面。我希望每个条件在条件文件输入下方都有一个文本框?
    • @Cyrillm_44 您可以简单地在reactive 元素中定义文本,然后让两个相同的output$errorText1output$errorText2 呈现reactive 元素的值。
    猜你喜欢
    • 2016-04-10
    • 2014-06-16
    • 1970-01-01
    • 1970-01-01
    • 2017-04-29
    • 2014-03-03
    • 2016-06-30
    • 2021-04-06
    • 2016-09-24
    相关资源
    最近更新 更多