4
votes

I have a fair-size R program that processes all text files (running LSA) in a given directory. It works, but it's not exactly user-friendly, and I'm trying to use Shiny to fix that. The problem is simply giving users a nice way to choose a directory and getting the path to it; then I can pass the path to my R program. Something like this:

fileInput("corpDir", label = "Choose the directory containing the corpus.")

...then, in Server.R, get the path via input$corpDir and pass it to the R program. But the fileInput widget does both too much (I don't want to upload the file, I just want to get its path) and too little (it returns the filename but not the path). And R's file.choose would be fine -- well, it'd be better if it allowed choosing directories, but having users choose a file within the directory is OK -- but I don't see how I can use file.choose from a Shiny UI. I've looked around on the RStudio site, including their gallery of examples, and tried to find an answer in both the Google group and here. I didn't find anything like this. TIA for any suggestions.

1
Web browsers aren't supposed to expose the fill path to a file because it's a security concern. See here. This is not specific to R or Shiny. - MrFlick

1 Answers

5
votes

The shinyFiles package can do that!

just install the package and run shinyFilesExample() to see how it works.

(NB: it only works if your shiny app runs locally, you can look at https://github.com/jcolomb/Viewer-file-concatenator and its readme for an example)