Skip to content

Commit

Permalink
Merge pull request #5 from erstearns/publish_app
Browse files Browse the repository at this point in the history
Updating master with latest, published app code
  • Loading branch information
erstearns authored Jun 11, 2019
2 parents 2b4a97d + de8faa5 commit 97ea823
Show file tree
Hide file tree
Showing 31 changed files with 1,571 additions and 155 deletions.
13 changes: 13 additions & 0 deletions CODE/CODE.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX
57 changes: 57 additions & 0 deletions CODE/shiny/animation/all_us_counties.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
############################################
# code author: erin stearns
# script objective: create animations to use in Shiny app (non-interactive)
# date: 15 May 2019
###########################################

rm(list = ls())

######################################################################################################
# -------------------------------------- set up environment ---------------------------------------- #
######################################################################################################
#load packages
pacman::p_load(data.table, tidycensus, tidyr, tidyverse,dplyr, feather, sf, tmap, viridis, RColorBrewer)

######################################################################################################
# -------------------------------------- load data -------------------------------------------------
######################################################################################################
#load spatial data
geodata <- readRDS('mod_geo_mockup/data/sf_acs5_2007_2017_w2010counties_v.Rds')
#transform spatial data to wgs84
geodata <- st_transform(geodata, crs = 4326)

######################################################################################################
# -------------------------------------- make tmap ---------------------------------------------------
######################################################################################################
# -- going to animate the black-white ratio
# rename
geo <- setnames(geodata, "blackwhite_ratio", "Black-White Ratio")

#explore var
summary(geo$`Black-White Ratio`)

#subset to contiguous US for visualization purposes
usa_contig <- geo[!geo$state_name %in% c("Alaska", "Hawaii", "Puerto Rico"),]
#bounding box for plotting
bb_contig <- st_bbox(usa_contig)
#take a look
plot(usa_contig["median_income"])

#create palette
div.pal = viridis::viridis(n = 8, direction = -1)
div.pal <- brewer.pal(9, "RdBu")

#create breaks
pb = c(0, .006, 0.02, 0.17, 1, 2, 4, 6, 7)

#create map
facet_anim <- tm_shape(geo, bbox = bb_contig) +
tm_polygons("Black-White Ratio", colorNA = NULL, palette = div.pal, breaks = pb) +
tm_facets(free.scales.fill = FALSE, ncol = 1, nrow = 1, along = "year") +
tm_shape(usa_contig) +
tm_borders(lwd = 2) +
tm_layout(legend.position = c("left", "bottom"))

#create animation
tmap_animation(tm = facet_anim, filename = "animation/blackwhiteratio.gif")

55 changes: 55 additions & 0 deletions CODE/shiny/app_dev/global.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
##############################################
# Code author: erin r stearns
# Code objective: create MoD shiny mock up - global script
# Date: 1.8.2019
#############################################

#####################################################
# --------------- TO DO ITEMS -----------------------
# - Make auto-subsetting in response to map panning
# - Make map plot 2 vals in -- base poly color and then centroid graduated symbols
# - add Github link if open source
# ---------------------------------------------------


######################################################################################################
# -------------------------------------- set up ---------------------------------------------------- #
######################################################################################################
library(shiny)
library(leaflet)
library(leaflet.extras)
library(RColorBrewer)
library(rgdal)
library(sf)
library(ggplot2)
library(ggvis)
library(shinydashboard)
library(dplyr)
library(fontawesome)
require(raster)
require(gstat)
library(OneR)

# -------------------------------------- load data -------------------------------------------------
#load spatial data
geodata <- readRDS('mod_geo_mockup/data/sf_acs5_2007_2017_w2010counties_v.Rds')
#transform spatial data to wgs84
geodata <- st_transform(geodata, crs = 4326)

#load aspatial data
adata <- readRDS('mod_geo_mockup/data/acs5_2007_2017_fin.Rds')

#model data
moddata <- readRDS('mod_geo_mockup/data/eb_rtg.Rds')

#spatial model data
geomod <- readRDS('mod_geo_mockup/data/eb_spatial_v.Rds')
#transform spatial data to wgs84
geomod <- st_transform(geomod, crs = 4326)

# -------------------------------------- app inputs defined ----------------------------------------
#state choices
state_names <- as.character(unique(adata$state_name))

#state choices for modeled data
mod_state_names <- as.character(unique(moddata$state_name))
Loading

0 comments on commit 97ea823

Please sign in to comment.