[英]'file' must be a character string or connection
我正在嘗試創建一個閃亮的應用程序,該應用程序上載表格,運行函數並顯示圖形和表格。 上傳文件工作正常,但是我無法運行該功能並輸出圖形和表格(我們現在僅關注表格)。 出現錯誤:
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")
)
server.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)
}
如果您未指定return
R將繼續執行podr_fun_graphs(inFile$datapath)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.