[英]How to use uploaded file for saving onto local server in R Shiny?
I want to use the file uploaded by the user and then link it to my other R script. 我想使用用户上传的文件,然后将其链接到我的其他R脚本。 I am unable to get access to the file right now. 我现在无法访问该文件。
UI -> fileInput("ghiFile", "Choose GHI File (.csv)",
accept=c('text/csv', 'text/comma-separated-values','text/plain', '.csv')),
The server.r file is empty as I am unable to get access of the file. server.r文件为空,因为我无法访问该文件。 I want to save the uploaded file on my local machine for now. 我想暂时将上传的文件保存在我的本地计算机上。
Like this: 像这样:
ui.R ui.R
ui <- shinyUI(fluidPage(
fileInput('target_upload', 'Choose file to upload',
accept = c(
'text/csv',
'text/comma-separated-values',
'.csv'
)),
DT::dataTableOutput("sample_table")
)
)
server.R server.R
library(shiny)
library(DT)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
df_products_upload <- reactive({
inFile <- input$target_upload
if (is.null(inFile))
return(NULL)
df <- read.csv(inFile$datapath, header = TRUE,sep = ";")
return(df)
})
output$sample_table<- DT::renderDataTable({
df <- df_products_upload()
DT::datatable(df)
})
}
)
Of course, you have to either make sure that the separator is correct, or also use an input for that. 当然,您必须确保分隔符正确,或者还要使用输入。 Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.