Need help storing multiple user-uploaded files in a temporary directory and accessing said directory in shiny app

I need to let the users upload multiple text files with data and save them to a temporary directory. Then I want to batch process all the text files in that temporary directory. Can anyone help me create this temporary directory and get the path to this temporary directory so that I can submit the directory address/name to a function that will then batch process all files in that directory? This is needed for a shiny app. I also want to host this app on shinyapps.io.

Snippets from ui.r
fileInput( "data", "Choose Monitor Files", multiple = TRUE, accept = c("text/csv","text/comma-separated-values,text/plain",".csv"))
Snippets from server.r
metadata_proc <- link_dam_metadata(metadata, result_dir = getwd())
the function link_dam_metadata attaches the metadata to respective files in the folder (by getwd()).

Also posted on reddit

1 Like

the system will give you a temporary directory, for each R session, on demand.

(mytempdir <- tempdir(check=TRUE))
dir.exists(mytempdir)
list.files(mytempdir)
1 Like

So all files uploaded to the app by the user will be always stored in mytempdir and I can access those files from mytempdir? Or do I have to transfer the files to mytempdir separately? In that case, how to do so? file.copy?

Figured it out, the solution is as follows:

file.copy(input$data$datapath, paste0(tempdir(), "\\", input$data$name), recursive = TRUE)

then the files can be accessed from dirname(tempdir()).

We have to first rename the files to their original name because browser-given names are serial numerics.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.