Thursday, January 07, 2016

R: 'file' must be a character string or connection

I was using Shiny app in R and I was trying to read a file using fileInput control but I faced the following error:

Listening on
Error in read.table(file = file, header = header, sep = sep, quote = quote,  :
  'file' must be a character string or connection

Problem code:

file <- read.csv(file=input$file1,head=TRUE,sep=",", stringsAsFactors=FALSE)
csv <- str(file)


inFile <- input$file1
if (is.null(inFile))

csv <- read.csv(inFile$datapath, header=TRUE, sep=",")

The resolution was to use datapath property of the input file and not the file itself.


  1. Fantastic blog extremely good well enjoyed with the incredible informative content which surely activates the learners to gain the enough knowledge. Which in turn makes the readers to explore themselves and involve deeply in to the subject. Wish you to dispatch the similar content successively in future as well.

    data science training in bhilai

  2. Highly appreciable regarding the uniqueness of the content. This perhaps makes the readers feels excited to get stick to the subject. Certainly, the learners would thank the blogger to come up with the innovative content which keeps the readers to be up to date to stand by the competition. Once again nice blog keep it up and keep sharing the content as always.

    Data Science Course in Bhilai