R闪亮的conditionalPanel显示两个条件 [英] R shiny conditionalPanel displaying both conditions
问题描述
我正在尝试使用多标签应用,我希望第二个标签的页面布局以第一个面板的输入为条件。基本上,如果第一个面板中的值为1,我希望第二个面板显示一组文件输入(如果用户在第一个面板中输入值2,那么我希望第二个面板显示2个文件输入)。目前,我的代码同时显示了这两种情况,但我不确定为什么。参见下面的可复制代码。
I am trying to a multi tab app, I want the the second tab's page layout to be conditional on an input from the first panel. Basically if the value in the first panel is 1 I want the second panel to display 1 set of file inputs if the user puts in the value 2 in the first panel then I want the second panel to display 2 file inputs. Currently my code displays both conditions, and I am unsure why. See the reproducible code below.
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)
推荐答案
这是因为您有 verbatimTextOutput( errorText)
在您的用户界面中两次。您无法在Shiny中做到这一点。输出只能包含在一个地方。
That's because you have verbatimTextOutput("errorText")
twice in your UI. You can't do that in Shiny. An output must be included at one place only.
这篇关于R闪亮的conditionalPanel显示两个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!