3

I've written a shiny app (server & ui) and it runs fine on my computer. Today I'm trying to host it on shinyapps.io 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
library(shiny)
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: https://jesstme.shinyapps.io/shinynames/

jesstme
  • 604
  • 2
  • 10
  • 25

2 Answers2

2

Would it be feasible to let the user upload the data from local computer using shiny browser button and then unzip it using read.table? For that read.table functionality, see this answer: https://stackoverflow.com/a/36047026/7860688 (copied here for the sake of completeness, assuming you only have one csv file inside that zip):

    data <- read.table("Sales.zip", nrows=10, header=T, quote="\"", sep=",")

Files can be uploaded using shiny fileInput function as below:

     fileInput("file1", "Choose CSV File",
    accept = c(
      "text/csv",
      "text/comma-separated-values,text/plain",
      ".csv")
    )

See the documentation here: https://shiny.rstudio.com/reference/shiny/latest/fileInput.html

Sal
  • 335
  • 2
  • 8
  • It's definitely feasible but not desirable. I'm hoping there's some way for folks to interact with the app without having to download something. – jesstme Aug 17 '17 at 04:26
1

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.

jesstme
  • 604
  • 2
  • 10
  • 25