Saving user selected file path (newbie)

I just (almost) completed my first shiny app after trying some other approaches, only to come to the end and discover a big problem (after spending week on this). I'm hoping there is a workaround and this can be salvaged. I have a somewhat specific question that will maybe get me over the finish line if there is a solution, and a more general question about my approach.

First, the app is intended to "look at" multiple files that user selects and produce a control grid of checkboxes and radio buttons for each file that are initialized using the file information, but that the user can override. I also do some reactive plotting, but that is somewhat besides the point. I'm using the basic fileInput() control to load files. The goal here is to generate two things: 1) a quarto produced HTML and 2) a new file which is created from the other files (it's an averaging process). I intended to do these outside of shiny in a separate quarto document. To communicate between the shiny app and the quarto I save the file names, paths, and control array values from the app into a file, with the intention that the quarto file will begin by reading these. My problem is that I did not realize that shiny will only save the temporary file paths. This causes two issues, I do not know in the quarto document where to open these files and I do not have the default path to save the new file. I could get around the first by accessing the temp folder, but these disappear as soon as the app is closed. Note that this app will only ever be run on local machines (so server is the machine). From my reading I understand to a degree that this use of temp directories is intended as a security measure for when apps are hosted on servers. So given all that: is there a way to salvage this and be able to write the actual file paths out of the app?

My more general question is: should I have used shiny for this in the first place? Although I take advantage of the reactivity for plotting, it's not necessary. My goal starting out was to build all this into a single quarto document that would 1) have the user load files, 2) create (cased on number of files selected) a gui with the file controls, 3) create the html and new file after the user indicates they have finished updating control. I ended up with shiny because I couldn't figure out a better way to build the ui.

Hard to be sure at this level of abstraction and not knowing the OS or the file system where the target files reside, but let’s start with {here} which is designed to make finding files not in the current directory easier.

d <- read.csv(here::here(“data/raw/file1.csv”)
e <- read.csv(here::here(“data/processed /file1.csv”)

Then, within a .RProj folder a script in a subfolder to the working directory,

“../R/take_in.R

knows to go up one to look for the data folder.

Probably a better way is a data frame with full pathnames of the files and with variables with which to form queries.

But that assumes that the files are on the user’s local drive or a network drive mapped to the local OS. If that’s not the case some data store with addressable URIs for the files is needed, along with any needed authentication facilities.

As far as Shiny goes, for the UI for file selection and spawning rendering jobs, the thing to remember is that when it is not calling an R function to run, say, a logistic regression, it’s only a fairly primitive HTTP layout front end and server backend. In your case it just serves as intermediary to take stain from user input, use it as argument to the underlying quarto CLI and send the resulting stdout to its destination as a file or back on the calling browser. This is Web 1.0 essentially and can be implemented in scores of frameworks in dozens of languages. So, just because it can be done in Shiny, there’s no necessary reason to do so if you already use different browser/server setups.

This topic was automatically closed 54 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.