【发布时间】:2015-05-15 09:02:15
【问题描述】:
我想在我的闪亮应用程序中有一个功能,当有人上传不是 .csv 格式的文件时,他们会收到警告,当他们以 .csv 格式上传时,它会打印表格。这是我的用户界面代码
shinyUI(
tabPanel("File Upload",
h4("File Upload"),
sidebarLayout(
sidebarPanel(
fileInput('file1', 'Choose CSV file to upload',
accept = c(
'text/csv',
'text/comma-separated-values',
'text/tab-separated-values',
'text/plain',
'.csv',
'.tsv'
)
)
),
mainPanel(
tableOutput('upload'),
h1(textOutput("warning1"))
)
)
)
)
和我的服务器代码
shinyServer(function(input, output) {
output$upload <- renderTable({
#assign uploaded file to a variable
File <- input$file1
#catches null exception
if (is.null(File))
return(NULL)
read.csv(File$datapath)
})
output$warning1 <- renderPrint({
upload<- input$file1
if (is.null(upload))
return(NULL)
if (upload$type != c(
'text/csv',
'text/comma-separated-values',
'text/tab-separated-values',
'text/plain',
'.csv',
'.tsv'
)
)
return ("Wrong File Format try again!")
})
}
【问题讨论】:
-
那么问题是什么,你得到的错误是什么?
-
我的问题是它似乎永远无法捕捉到正确的文件类型。即使不是 csv 格式,它也会打印每种格式。 $type 似乎不起作用并发送一个空值
标签: r csv file-upload shiny rstudio