4

How can I select a default file when uploading a file in R/Shiny?

This is the shiny app I try to modify.

As default, I want to see something like /tmp/test.csv instead of "No file selected".

Any ideas?

Revan
  • 2,072
  • 4
  • 26
  • 42

1 Answers1

2

This is not possible due to security reasons.

See How to set a value to a file input in HTML?

Since your app will run in the user's browser, a possibility for you to preselect a local file path would mean you could steal the user's files (you could make the file upload button look like something else to bait the user and make them click it, or just trigger the upload programmatically). Therefore, it is not possible to preselect a file.

Community
  • 1
  • 1
CherryDT
  • 25,571
  • 5
  • 49
  • 74
  • Thanks for your answer, sounds reasonable. Can I set a default folder (where to look for files when I click the upload folder)? – Revan May 17 '16 at 12:15
  • No, for similar reasons. In general, web pages have neither access to nor knowledge about the file system on the user's computer. (You will also notice that the "path" sent to the website during upload will be something like `C:\fakepath\thefile.txt` and not the real path.) – CherryDT May 17 '16 at 12:19