I am building a web app for users to upload file and store the data in PostgreSQL every month; I want to specify and extract the month from the file name uploaded; something like "Utilization_summary_201511.csv".
However, I am getting trouble getting the file name, I tried 2 ways below but both in vain. In server.R
1. Use read.csv
filename<-renderText({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
file<-read.csv(inFile$datapath, header=TRUE ,sep=",")
name<-basename(file)
name
})
2. Combine file.choose() and read.csv
filename<-renderText({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
filename<-file.choose()
data <- read.csv(filename, header=TRUE ,sep=",", skip=1)
name<-basename(filename)
name
})
and in ui.R:
textOutput("filename")
It should be not so hard, and I've been trying to coming out solution for few days, thanks in advance for any ideas and suggestions.
file
is a dataset object. You need a extract the basename from the string. In the second case,filname
andfilename
are different – akrun