我应该从fileInput
中读取文件,但是当我运行该应用程序时出现此错误:
警告:fread错误:input =必须是包含文件名的单个字符串,包含至少一个空格的系统命令,以'http [s]://','ftp [s]开头的URL: //”或“ file://”,或者输入数据本身至少包含一个\ n或\ r
我的闪亮代码:
library(shiny)
library(data.table)
library(DT)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file","Operation Record",
multiple = TRUE,
buttonLabel = "Browse...",
placeholder = "No file selected",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv")
)
),
mainPanel(
DTOutput("table")
)
)
)
server <- function(input, output) {
output$table <- renderDT({
originalDataset <- fread(input = input$file$datapath,encoding = "UTF-8",
select = c("Date","ID","Type","EMail","ClientType"))
return(originalDataset)
})
}
# Run the application
shinyApp(ui = ui, server = server)
有什么建议吗?谢谢。
答案 0 :(得分:2)
运行应用程序时,input$file
为NULL
,直到您选择文件为止。您需要一个req
:
server <- function(input, output) {
output$table <- renderDT({
req(input$file)
originalDataset <- fread(input = input$file$datapath,encoding = "UTF-8",
select = c("Date","ID","Type","EMail","ClientType"))
return(originalDataset)
})
}