I am currently working on a shiny app where I have created a fileInput button through which the user can browse and select a zip file and the file will get unzipped and stored in the chosen directory as specified through the argument 'exdir' in the function unzip().
The next step involves accessing the filepath for a csv file inside this unzipped file. The structure of the unzipped file is somewhat of a folder within a folder which is again inside a folder.
The conventional way of writing the filepath for this csv will be something like "C:\x\y\z\file.csv" where z contains the csv file and is within y which is within another folder x. But since it's a shiny app deployed on cloud, users might use various zip files although containing the same number of folders but different folder names other than a fixed "x","y","z " but the said zip file will always contain the csv file 3 folders deep. Hence it's possible to mention the path in terms of some x,y or z for general purpose.
I am looking to access this csv file which will have the same name for all users (file.csv) with only the preceding folder names being different each time. Is there any other way to get this filepath than manually defining it everytime as written above?
Hi, you can search the "file.csv" since you know its name, using the "dir" command with recursive=T. And it should work even if the number of folders is not 3.
you need to carefully set selected_folder to the folder of the uploaded zip (exdir). Otherwise, if you use the root folder, it will return all "file.csv" files in all the subfolders.
Thanks for the insight. This is really helpful.
Can you also help me out with an error?
While unzipping a zipped file in a temporary file location I am getting the following warning/error :
What OS you're using? and what's the output of tempdir() ?
maybe the tempdir isn't writable, if this is the case, you should change it or allow permission to the R user to write on that folder or run R/RStudio as Administrator/root.