R具有多个文件输入的条件面板
我在R中遇到了条件面板的异常行为。我想有多个文件输入,用户可以上传取决于多少文件,他们想要的。下面是可还原代码。这个问题是如果条件大于1,我不能用csv文件填充所有文件??第二次我可以,但第一次不行R具有多个文件输入的条件面板,r,shiny,conditional,R,Shiny,Conditional,我在R中遇到了条件面板的异常行为。我想有多个文件输入,用户可以上传取决于多少文件,他们想要的。下面是可还原代码。这个问题是如果条件大于1,我不能用csv文件填充所有文件??第二次我可以,但第一次不行 library('shiny') library('shinythemes') ## adding the conditional statements ui = navbarPage("Page Title", tabPanel("Panel 1", sidebarPanel(
library('shiny')
library('shinythemes')
## adding the conditional statements
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", multiple = F),
p("Click the button to check the data was read in correctly")
),
fixedRow(
column(12,
verbatimTextOutput("errorText1")
)
)
)
)
),
conditionalPanel(condition = "input.n_values == 2",
fixedPage(theme = "flatly",
fixedRow(
column(2,"First Column",
fileInput("File1", "Choose a CSV files", multiple = F),
p("Click the button to check the data was read in correctly")
),
column(2,"Second Column",
fileInput("File2", "Choose a CSV files", multiple = F),
p("Click the button to check the data was read in correctly")
),
fixedRow(
column(12,
verbatimTextOutput("errorText2")
)
)
)
)
)
)
)
server = function(input, output,session) {
## Call the error message function and print
output$errorText1 <- renderText({
validate(
if (input$n_values == 1) {
need(!is.null(input$File1)
, 'You need to input the files before we can validate the data. Please select all the necessary files.')
}
)
validate("allgravy")
})
output$errorText2 <- renderText({
validate(
if (input$n_values == 2) {
need(!is.null(input$File1) & !is.null(input$File2)
, 'You need to input the files before we can validate the data. Please select all the necessary files.')
}
)
validate("allgravy")
})
}
shinyApp(ui, server)
library('shinny')
图书馆(“shinythemes”)
##添加条件语句
用户界面=
navbarPage(“页面标题”,
选项卡面板(“面板1”,
侧栏面板(
##加上名字,
##进行分析的调查次数
数值输入(“n_值”,“下一面板中的列数:”,1,最小值=1,最大值=2)
),
主面板(
标签$div(
h2(“主页”)
)
)
),
选项卡面板(“面板2”,
conditionalPanel(condition=“input.n\u values==1”,
fixedPage(theme=“flatly”,
固定道(
第(2)列,“第一列”,
文件输入(“文件1”,“选择CSV文件”,多个=F),
p(“单击按钮检查数据是否正确读取”)
),
固定道(
第(12)栏,
逐字输出(“errorText1”)
)
)
)
)
),
conditionalPanel(condition=“input.n\u values==2”,
fixedPage(theme=“flatly”,
固定道(
第(2)列,“第一列”,
文件输入(“文件1”,“选择CSV文件”,多个=F),
p(“单击按钮检查数据是否正确读取”)
),
第(2)栏,“第二栏”,
文件输入(“文件2”,“选择CSV文件”,多个=F),
p(“单击按钮检查数据是否正确读取”)
),
固定道(
第(12)栏,
逐字输出(“errorText2”)
)
)
)
)
)
)
)
服务器=功能(输入、输出、会话){
##调用错误消息函数并打印
output$errorText1问题是您在代码中使用了两次相同的元素;您在代码中使用了两次fileInput(“File1”,“chooseacsv files”,multiple=F)
,这是不允许的(我认为与此有关)
您可以通过只使用元素一次并更改您的条件来解决此问题。例如:
library('shiny')
library('shinythemes')
## adding the conditional statements
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 | input.n_values == 2",
fixedPage(theme = "flatly",
fixedRow(
column(2,"First Column",
fileInput("File1", "Choose a CSV files", multiple = F),
p("Click the button to check the data was read in correctly")
),
conditionalPanel(condition = "input.n_values == 2",
column(2,"Second Column",
fileInput("File2", "Choose a CSV files", multiple = F),
p("Click the button to check the data was read in correctly")
)
)
),
fixedRow(
column(12,
verbatimTextOutput("errorText2")
)
)
)
)
)
)
)
server = function(input, output,session) {
## Call the error message function and print
output$errorText1 <- renderText({
validate(
if (input$n_values == 1) {
need(!is.null(input$File1)
, 'You need to input the files before we can validate the data. Please select all the necessary files.')
}
)
validate("allgravy")
})
output$errorText2 <- renderText({
validate(
if (input$n_values == 2) {
need(!is.null(input$File1) & !is.null(input$File2)
, 'You need to input the files before we can validate the data. Please select all the necessary files.')
}
)
validate("allgravy")
})
}
shinyApp(ui, server)
library('shinny')
图书馆(“shinythemes”)
##添加条件语句
用户界面=
navbarPage(“页面标题”,
选项卡面板(“面板1”,
侧栏面板(
##加上名字,
##进行分析的调查次数
数值输入(“n_值”,“下一面板中的列数:”,1,最小值=1,最大值=2)
),
主面板(
标签$div(
h2(“主页”)
)
)
),
选项卡面板(“面板2”,
conditionalPanel(condition=“input.n_values==1 | input.n_values==2”,
fixedPage(theme=“flatly”,
固定道(
第(2)列,“第一列”,
文件输入(“文件1”,“选择CSV文件”,多个=F),
p(“单击按钮检查数据是否正确读取”)
),
conditionalPanel(condition=“input.n\u values==2”,
第(2)栏,“第二栏”,
文件输入(“文件2”,“选择CSV文件”,多个=F),
p(“单击按钮检查数据是否正确读取”)
)
)
),
固定道(
第(12)栏,
逐字输出(“errorText2”)
)
)
)
)
)
)
)
服务器=功能(输入、输出、会话){
##调用错误消息函数并打印
输出$errorText1谢谢你解决了这个问题,我想知道你是否对上述情况有任何评论,但是有10个条件,看起来很快就会变得一团糟
library('shiny')
library('shinythemes')
## adding the conditional statements
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 | input.n_values == 2",
fixedPage(theme = "flatly",
fixedRow(
column(2,"First Column",
fileInput("File1", "Choose a CSV files", multiple = F),
p("Click the button to check the data was read in correctly")
),
conditionalPanel(condition = "input.n_values == 2",
column(2,"Second Column",
fileInput("File2", "Choose a CSV files", multiple = F),
p("Click the button to check the data was read in correctly")
)
)
),
fixedRow(
column(12,
verbatimTextOutput("errorText2")
)
)
)
)
)
)
)
server = function(input, output,session) {
## Call the error message function and print
output$errorText1 <- renderText({
validate(
if (input$n_values == 1) {
need(!is.null(input$File1)
, 'You need to input the files before we can validate the data. Please select all the necessary files.')
}
)
validate("allgravy")
})
output$errorText2 <- renderText({
validate(
if (input$n_values == 2) {
need(!is.null(input$File1) & !is.null(input$File2)
, 'You need to input the files before we can validate the data. Please select all the necessary files.')
}
)
validate("allgravy")
})
}
shinyApp(ui, server)