1
votes

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.

1
In the first case, file is a dataset object. You need a extract the basename from the string. In the second case, filname and filename are differentakrun
thanks @akrun, I already revised the 2nd case typo and re run but still not work; for case 1, would you please explain more? Thanks.Samoth

1 Answers

2
votes

You might want to try inFile$name, rather than inFile$datapath. According to the shiny fileInput documentation:

name The filename provided by the web browser.

datapath The path to a temp file that contains the data that was uploaded.

Good luck!