4

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.

Don Byrd
  • 41
  • 1
  • 3
  • 2
    Web browsers aren't supposed to expose the fill path to a file because it's a security concern. [See here](http://stackoverflow.com/questions/4176377/how-to-get-the-full-path-of-the-file-from-a-file-input). This is not specific to R or Shiny. – MrFlick Dec 01 '14 at 21:02

1 Answers1

5

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)

Julien Colomb
  • 508
  • 4
  • 20