Shinylive access to local folders

Does a Shinylive application running on a PC have full access to folders on the PC (assuming appropriate file permissions)? I have a script I would like to turn into an app, but there is a possible deal breaker: it needs to be able to rename files selected by the user. It also needs to create a zip archive of those files, which I know I can do in a Shiny app if I have the files uploaded to the app.

Thanks for any help or suggestions.

If the user is supposed to select those files and the files reside on the server please have a look at this library:

Please be aware of the potential risk - the access should be limited to a req. minimum.

Usually server side files are made available via the www folder or via addResourcePath:

However, I'm not sure if one or the other works with shinylive.

Thanks, that's interesting. For my case, though, the app would be running locally on a PC (for instance, using shinylive) and the files would be on the same PC, in a folder accessible by the user running the app.

Then I guess you don't need to introduce the files as static resources to the webserver.

The R session running shiny can access the filesystem on the host just as the R script you mentioned. However, I guess this will not be the case for shinylive as the browser runs the R session.

Nevertheless, how would you like to present the files to the user?

Another option would be:

Please also check:

Again, thanks for the links. Ideally, the app would be as follows.

  • The user starts with an Excel file and a bunch of supporting files (Word or PDF) sitting in a directory on the machine running the app.

  • The app presents a UI with some instructions and a file input to choose the Excel file.

  • When the user selects the spreadsheet file, the app reads the spreadsheet, extracts the names of the Word/PDF files, and checks to see if they are all present. If any are missing, the app alerts the user and stops.

  • If all files are present, the app makes some changes in the spreadsheet, renames each of the Word/PDF files using info from the spreadsheet, writes out the modified spreadsheet to a file in the same directory and zips up everything that can't outrun it.

I do this right now using an R Markdown file, in which I edit a line or two of code to point to the correct folder and spreadsheet file and then execute code chunks one by one (necessary because a missing file can create problems with what follows). I'm OK using the .Rmd file, but if I have to hand this off to someone I'd rather make it a self-contained program with a more typical user interface. Shinylive would meet my needs if only it would let me rename files in a local folder.

If you are targeting windows systems you could check RInno instead of shinylive:

Or you stick with shinylive and the users need to upload the relevant files.

Have a look at this. I think you might be able to adapt it to your needs:

If it helps you, I'd only ask you to please give credit by referencing my repo according to the GPL-3.0 license :wink:

Btw I don't remember well how I designed all of this, it was quite a long time ago and I haven't updated it in a while. But it seems like I created a new version for "path input" (where you can choose between folder and file(s)) that I ended up using.
You can see it in use here.

Thanks. I'll definitely take a look at this.

Again, thank you. I could probably get by with the limitation to Windows (especially if the app could be run on Linux using wine). I guess the first step is to experiment with Shiny and see if "uploading" the files from the user's PC to itself and renaming them works. If so, Shinylive will likely be the solution.

I'd also suggest trying to implement a shinylive approach as it is more universal. The overhead of "uploading" or in this case just copying the files to a temp folder should be negligible.

It worked with Shinylive, with one tweak. "Uploading" from the client PC to temp directories on the client PC posed no problems. There was a problem with creating a zip archive for download.

The code initially used utils::zip, which resulted in a 500 server error tracking to a message that "The system() function is unsupported under Emscripten." This was because utils::zip() uses a zip utility presumed to be installed on the user's PC (and apparently accessed via the unsupported system() function). The fix was to switch to the zip library (and use zip::zip()), which necessitated some tweaks to the arguments supplied to zip() but ended up working just fine.

2 Likes