forked from thfield/sf-planning-pipeline-report
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d479848
commit 0b2719a
Showing
13 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Choropleth Shiny Server | ||
======================= | ||
|
||
`run_shiny_server.sh` will take a CSV file as an argument, and it will start a shiny app that | ||
plots a choropleth of the SF neighborhoods using that data. | ||
|
||
For example: | ||
|
||
``` | ||
./run_shiny_server.sh ../data/San_Francisco_Development_Pipeline_2015_Quarter_4.csv | ||
``` | ||
|
||
The shiny app will allow you to select which variable the choropleth color scale corresponds to. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
library(shiny) | ||
|
||
runApp() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
# Usage: ./run_shiny_server.sh <path to csv> | ||
Rscript run.R "$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
library(plyr) | ||
library(rgeos) | ||
library(maptools) | ||
library(stringr) | ||
library(ggplot2) | ||
library(shiny) | ||
|
||
args <- commandArgs(trailingOnly = TRUE) | ||
|
||
df = read.csv(args[1], stringsAsFactors = FALSE) | ||
|
||
neighborhoods <- readShapeSpatial("../gis/shp/neighborhoods.shp") | ||
neighborhoods <- fortify(neighborhoods, region = "nhood") | ||
|
||
# Try to standardize identifiers. | ||
neighborhoods$id <- str_trim(toupper(neighborhoods$id)) | ||
df$NEIGHBORHOOD <- str_trim(toupper(df$NEIGHBORHOOD)) | ||
|
||
plotChoropleth = function(data, variable) { | ||
ggplot() + | ||
geom_map(data = data, | ||
aes_string(map_id = "NEIGHBORHOOD", fill = variable), | ||
map = neighborhoods) + | ||
geom_polygon(data = neighborhoods, aes(x=long, y = lat, group = group), fill = NA, color = "black") + | ||
expand_limits(x = neighborhoods$long, y = neighborhoods$lat) | ||
} | ||
|
||
shinyServer(function(input, output) { | ||
output$choropleth <- renderPlot({ | ||
plotChoropleth(df, input$variable) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require(shiny) | ||
require(plyr) | ||
|
||
args <- commandArgs(trailingOnly = TRUE) | ||
df = read.csv(args[1], stringsAsFactors=FALSE) | ||
|
||
# Only integer columns will work well for the choropleth | ||
options = names(colwise(class)(df)[,colwise(class)(df) == "integer"]) | ||
variableSelector = selectInput(inputId = "variable", | ||
label = "Variable", | ||
choices = options, | ||
selected = "UNITS") | ||
|
||
shinyUI(fluidPage( | ||
titlePanel("SF Housing Pipeline"), | ||
sidebarLayout( | ||
mainPanel( | ||
plotOutput("choropleth", height = "700px") | ||
), | ||
sidebarPanel(variableSelector) | ||
) | ||
)) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
ogr2ogr -nlt POLYGON -skipfailures "$2".shp "$1" OGRGeoJSON |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] |
Binary file not shown.
Binary file not shown.