Davit Sargsyan
Davit Sargsyan

Reputation: 1284

How to restrict Shiny fileInput to text files only?

I want to restrict my file browser to displaying only the types of file I specify, e.g. .txt files only. The only relevant snippets of a code I found are like the following:

fileInput("in_file", 
          "Input file:",
          accept=c("txt/csv", "text/comma-separated-values,text/plain", ".csv") 

However, this does't filter the files showing in the browser to just .txt and .csv. Any ideas?

Upvotes: 4

Views: 2569

Answers (1)

DeanAttali
DeanAttali

Reputation: 26333

As far as I understand, that's the right way to do it. If you view your app in the RStudio viewer it wouldn't do anything, but in a browser it should. I'm using Chrome and I just ran that code and it did in fact only show me txt and csv files.

Of course the user can still choose to view other files by going to the little select box and choosing to view all files, but they have to consciously choose to do that. By default only csv and txt files will be shown

Upvotes: 7

Related Questions