r - 'file' 必须是字符串或连接
问题描述
我正在尝试创建一个闪亮的应用程序,它可以上传表格、运行函数并显示图表和表格。上传文件工作正常,但我无法运行该函数并输出图形和表格(我们现在只关注表格)。我收到错误:
Warning: Error in read.table: 'file' must be a character string or connection
我已经在 R 中单独运行了该函数,并且可以很好地处理所需的输出。我尝试了不同的读取函数和不同的分隔符/定界符,并在响应式 renderPlot 函数中读取函数(如上一篇文章所述)。下面是我一直在处理的代码片段:
ui.R:
fileInput("file1",
"Load Input File",
accept = c("text/csv", "text/comma-separated-values,text/plain",".csv")
)
服务器.R:
execute = observeEvent(input$runButton, {
output$plot1 = renderPlot({
inFile = input$file1
if (is.null(inFile)) {
print(NULL)
}
podr_fun_graphs(inFile$datapath)
})
}
podr_graphs 函数:
podr_fun_graphs <- function(p) {
df1 <- read.delim(p, sep = "\t")
... # From here there is some data cleaning and manipulation of df1
}
几周前类似的代码还在工作,我做了一些小改动,然后就坏了。将不胜感激任何帮助来解决这个问题。
谢谢
解决方案
问题出在你的if
陈述中。你已经写了print(NULL)
。但它应该是:
if (is.null(inFile)) {
return(NULL)
}
podr_fun_graphs(inFile$datapath)
如果您不指定,R 将继续执行return
。
推荐阅读
- python - 字符计数到字典中作为字符的值?
- c# - C# 虚拟串口问题!错误命令后不恢复
- python - Pytest:删除被测试函数创建的文件
- css - 我正在尝试从其他几个中格式化一个特定的验证消息
- android - arm-linux-androideabi-4.9 还是 arm-eabi-4.8?
- c - 执行二进制文件时出现“exec 格式错误”
- javascript - 有没有办法使用 Javascript 抓取动态页面
- sql - 在一次查询中创建一个新表并从 SQL Server 2017 中的旧表添加数据
- javascript - 在Javascript中将非unicode二进制字符串转换为字节数组
- amazon-web-services - 带有 docker 多容器和 Node 的 EB