Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restrict Shiny fileInput to text files only?

Tags:

rstudio

shiny

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?

like image 262
Davit Sargsyan Avatar asked Mar 16 '23 20:03

Davit Sargsyan


1 Answers

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

like image 134
DeanAttali Avatar answered Apr 08 '23 23:04

DeanAttali