7
votes

I'm using reactive function in order to do the 2 things at the same time:

  1. read the upload csv file;
  2. get the file name

see the code below:

 file_info<-reactive({

     filename <- file.choose()
     data <- read.csv(filename, skip=1)
     file_name <- basename(filename)

   })

however, the file_info() only contains the file_name, which forces to me to write another reactive function to get the data uploaded:

 Raw<- reactive({
     inFile <- input$file1

     if (is.null(inFile))
      return(NULL)
    Raw<-read.csv(inFile$datapath, header=TRUE ,sep=",") 
 })

I think there should be another efficient way to do this, thanks in advance for any suggestions.

1
Add at the end of file_info: list(data=data, file_name=file_name). Then, when you call file_info() you get a list with the file name and the data.nicola
If you really want both together, @nicola 's answer is the way. But you could use a fileInput instead of file.choose.user5029763

1 Answers

0
votes

Return values in R are meant to be contained in a single object, either in functions or in reactives. However, I would recommend gathering your content in a list and get the return values from your reactive in a temp variable. Then, get what you want from this temp variable. Like:

myReactive({
  # does stuff

  return(
    list(
      val1 = val1,
      val2 = val2
    )
  )
}}

.tmp <- myReactive()
x <- .tmp$val1
y <- .tmp$val2