Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do I do when Shiny won't read my files?

My Shiny app works on my local computer, but when I upload it to the shinyapps.io server, I get an error message that says:

Warning in gzfile(file, "rb") : cannot open compressed file './data/treemap_master.rds', probable reason 'No such file or directory' Error in value[3L] : cannot open the connection Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> Execution halted

You can find the full github repository at: https://github.com/ethantenison/UWATX_Shiny_App

This app is supposed to be uploaded to the Shinyapps linux server. I've made sure that all of the files use relative paths, that the app.R file is inside the directory containing all my files, and I've updated all of my packages including R itself.

library(devtools)
library(shinydashboard)
library(shiny)
library(V8)
library(shinyjs)
library(rintrojs)
library(highcharter)
library(RColorBrewer)
library(htmlwidgets)
library(dplyr)
library(stringr)
library(magrittr)
library(viridis)
library(viridisLite)
library(readr)
library(tidyr)
library(leaflet)
library(treemap)
library(leaflet.extras)
library(sf)

# ------------------------------- #
# ------------------------------- #
# ------------------------------- #
# ------------SECTION:----------- #
# ----Reference Data & Styles---- #
# ------------------------------- #
# ------------------------------- #
# ------------------------------- #

# IMPORT MAP STYLES
blank <- "https://api.mapbox.com/styles/v1/mrw03b/cjjd6srrl7ot42so3cbjxn6ot/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoibXJ3MDNiIiwiYSI6IlYwb2FiOWcifQ.RWUm2a87fEC9XrDxzvZKKg"
northstar <- "https://api.mapbox.com/styles/v1/mrw03b/cj48wz0xh15td2st5hcmeqmsv/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoibXJ3MDNiIiwiYSI6IlYwb2FiOWcifQ.RWUm2a87fEC9XrDxzvZKKg"
map_attr <- "© <a href='https://www.mapbox.com/map-feedback/'>Mapbox</a> | Map © <a href='http://www.unitedwayaustin.org/our-work/2gen/'>United Way of Greater Austin</a>"

full_zips_list <- "78705|78617|78641|78645|78652|78653|78660|78701|78702|78703|78704|78719|78721|78722|78723|78724|78725|78727|78728|78730|78731|78732|78733|78734|78735|78736|78738|78739|78741|78742|78743|78744|78745|78746|78747|78748|78749|78750|78751|78752|78753|78754|78756|78757|78758|78759|78654|78610|78621|78615|78669|78737|78620|78726"

filter_out <- "78712|78743"

treemap_master <- read_rds('./data/treemap_master.rds') %>%
  ungroup() %>%
  mutate(age = as.character(age))

#TREEMAP DATA - ZIP & NEEDS
needs_zip_treemap <- read_rds('./data/needs_zip_treemap.rds') %>%
  ungroup() %>% 
  janitor::clean_names() %>%
  mutate(day = as.character("01"),
         month = as.character("01")) %>% 
  unite(date, c("year", "month", "day"), sep = "-") %>% 
  mutate(date = as.Date(date, "%Y-%m-%d")) %>% 
  rename(year = date)

travis_dl <- read_rds('./data/data_4_download.rds')

travis <- read_rds('./data/data_4_analysis.rds') %>%
  filter(!str_detect(zipcode, filter_out))  %>% 
  group_by(Year, measure) %>% 
  mutate(rank = dense_rank(desc(value))) %>% 
  ungroup()

travis_summ <- read_rds('./data/summ211.rds')

travis_county_sf <- read_rds('./data/traviscounty_boundary.rds')

The app is supposed to look something like this: https://uwatx.shinyapps.io/211Explorer/

You can find the full error message here: https://uwatx.shinyapps.io/UWATX_Shiny_App/

like image 904
ethan tenison Avatar asked Aug 21 '19 19:08

ethan tenison


People also ask

Why does my app work locally but not on my shiny server?

Your application may be dependent on packages that are installed and loaded in your environment, but aren't installed for the correct user on the Shiny Server. Make sure that all necessary packages are installed for the same user set under run_as in your Shiny Server configuration file.

How do you save data on the shiny app?

The most trivial way to save data from Shiny is to simply save each response as its own file on the current server. To load the data, we simply load all the files in the output directory. In our specific example, we also want to concatenate all of the data files together into one data.

Is shiny app secure?

shinyapps.io is secure-by-design. Each Shiny application runs in its own protected environment and access is always SSL encrypted. Standard and Professional plans offer user authentication, preventing anonymous visitors from being able to access your applications.


1 Answers

From RStudio Shiny lesson 5 - "The directory that app.R appears in will become the working directory of the Shiny app".

Accordingly, you need too make sure that all the data files are in same or sub-folder of the folder with app.R. Basically -

project_dir
    |
     - app.R
    |
     - data
         |
          - treemap_master.rds

# for above structure use 
read_rds('data/treemap_master.rds') 

As per your post, "I've made sure that all of the files use relative paths, that the app.R file is inside the directory containing all my files" is probably where you went wrong.

like image 82
Shree Avatar answered Oct 05 '22 02:10

Shree