Problems inputFile and read.table in Shiny


I'm developing a shiny app.
With this I want to download data to manipulate it.

In ui.R

# To rename data
textInput("data_name", "",  placeholder = "Example : 20190625_Data_Name"),

# To download file
fileInput("data_exp","", multiple = TRUE),

#To launch process     
actionButton("import", "Download")

In server.R

UploadData <- reactive({
    file1 <- input$data_exp
observeEvent(input$import, {
        if (is.null(input$data_name) || input$data_name == "") {
            session = session,
            title = "Error...",
            text = "Nom des données vide",
            type = "error"
        } else {
          upload_data(input$nom_data, UploadData())
            session = session,
            title = "Done !",
            text = "Vos données ont bien été traitées",
            type = "success"

My function upload_data(data_name, data_table) is correct, because without the application I get what I want.

However... it's the opposite when my app run. Actually, I have two kind of error message :

Warning: Error in read.table: first five rows are empty: giving up
  79: stop
  78: read.table
  77: read.csv
  76: upload_data [myPath/App/Functions/upload_data.R#20]
  72: observeEventHandler [myPath\App/server.R#41]
   1: runApp

Or otherwise, read.table have to contain character or string something like that.
After the size of the files is greater than 5MB

But to explain everything properly, here is the function code

upload_data <- function(nom_data, data_table){

  data_path <- "myPath/Data/"
  data_path <- paste0(data_path , nom_data)
  raw_data <- transpose(data_table)
  write.csv(raw_data, file = paste0(data_path, "/", nom_data, ".csv"), row.names = FALSE) <- read.csv(paste0(data_path,  "/", nom_data, ".csv"))
  assign(nom_data,, envir = .GlobalEnv)
  .GlobalEnv$liste_data <- append(.GlobalEnv$liste_data, toString(nom_data))

Thank you in advance for your answers

Hi. I tried out your code and was able to get everything working except for upload_data. I had trouble getting that working on my machine so I just took it out and it seems like the upload and table reading is working just fine (I tested by calling write.table(iris, "iris.txt").

Here's the code I ran:

A couple of thoughts:

  • it might be interesting to put a browser() call in upload_data so that you can interactively explore the app after the data gets uploaded.
  • you might want to randomly generate the filenames instead of letting the user specify them. Users could do malicious things like put a "../" inside of their file name to write data outside of the directory where you want them writing.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.