jesstme jesstme - 5 months ago 62
R Question

Read csv from zip into shiny app without relying on local directories

I've written a shiny app (server & ui) and it runs fine on my computer. Today I'm trying to host it on and having some trouble. I can't pull data from my local machine, it needs to be housed online somewhere. But the source data is only available online as a zip. I've found a few resources on how to use R to download a zip to one's local machine, but they all seem to require putting the file in a local temporary directory, and I don't think I can do that with a hosted shiny app. So my question is
how to unzip and then access/load/use CSV files directly within R/Shiny.

Relevant snippet of code is below. This is the section I need to replace. Let me know if it would be helpful to post more code--I know that's expected but in this case I'm not sure it would help.

#load data
base <- read.csv("/Users/OldJess/Dropbox/R Stuff(Home)/ShinyNames/data/NationalNames.csv",
stringsAsFactors = FALSE,
na.strings = c("NA","","#MULTIVALUE"))

My shiny app is here:

Answer Source

I hadn't realized that Shiny allows me to upload the original source data (as a CSV) from my computer for use in my app, along with the ui & server files. There are file size limits but the solution is working well for me.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download