In a shiny app, if you click on the open file dialog box it runs this reactive funtion:
data <- reactive({
file <- input$file
req(file)
if (is.null(file)) {
return(NULL)
}
fpath <- file$datapath
if (endsWith(".zip", fpath)) {
fpath <- unzip(zipfile = fpath, files = NULL, overwrite = TRUE)
}
data <- read.csv(fpath, header = TRUE)
data
})
For CSV files, it runs as expected. For ZIP files, fpath doesn't become the path to the unzipped CSV - it stays as the temporary ZIP file path and causes the read.csv function to get an error. This code runs as expected outside of the reactive. Every attempt to insert debugging code into this reactive or step through it in the debugger is ignored. It will not print to stderr, etc.
How do I unzip the ZIP file and read in the CSV file? This article doesn't fully answer the question. I think there is something in this article but I can't understand it outside of my own context.
Do you have a more complete exemple ?
For me, it's working, by just changing if (endsWith(".zip", fpath))
by if (endsWith(fpath, ".zip"))