How to allow R shiny to read .xlsx and csv files without conflicts?



I am trying to allow users to upload .xlsx and csv files but always get errors.

              inputId = "file",
              label = "",
              multiple = TRUE,
              accept = c("text/csv",".xlsx",
              placeholder = "Use Ctrl key to choose files"


    read.csv(input$file$datapath) -Here, how to deal with .xlsx files


Because you can’t use read.csv to read Excel files, they are not CSV files.
Try read_excel from {readxl}.

So you can do things like, if it is csv you use read.csv, if it is xlsx, use readxl

You didn’t provide the full code, so here I can just give you some snippets:

if(stringr::str_ends(input$file$datapath, "csv")) {
} else if (stringr::str_ends(input$file$datapath, "(xlsx|xls)")) {

Answered By – lz100

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More