【发布时间】:2015-05-11 20:28:43
【问题描述】:
我试图在一个函数中同时提供上传 csv 和 excel 表的选项。我正在使用 read.csv 从 XLConnect 包中读取 csv 文件和 readworksheetfromfile 来读取 excel 文件。我为此使用了 trycatch 块,但是当 csv 文件通过 readworksheetfromfile 函数传递时,我仍然收到错误。我的 tryblock 看起来像
filedata <- reactive({
infile <- input$templatedfile
if (is.null(infile)) {
# User has not uploaded a file yet
return(NULL)
}
importedfile = tryCatch({
read.csv(infile$datapath,stringsAsFactors=FALSE)
}, finally = {
readWorksheetFromFile(infile$datapath,sheet=1,check.names=FALSE)
})
})
【问题讨论】:
-
您收到什么错误?
-
您可能会考虑使用 rio 来自适应地读取各种文件格式(它使用 readxl 而不是 XLConnect 来导入 Excel 文件):cran.r-project.org/web/packages/rio
-
@Thomas,
rio是否解决了当前readxl与shiny有关文件名的问题?见问题here -
我没试过,但应该可以。
标签: r excel csv shiny shiny-server