/
app.R
120 lines (108 loc) · 4.51 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
library(shiny)
library(Rcpp)
library(httpuv)
library(plotly)
#devtools::install_github('rstudio/httpuv')
#install.packages("shiny", version='1.6')
#load in helper document
source("scratch_alr.R")
source("maps_AR.R")
#options(shiny.minified=FALSE)
# User interface ----
ui <- fluidPage(
titlePanel("Food Insecurity in Arlington County"),
sidebarLayout(
sidebarPanel(
## Quick synopsis of app's purpose
helpText("Create maps of Arlington County Food Security"),
## drop down widget so user can select which race to create map for
selectInput("var",
label = "Choose a variable to display",
choices = c("Percent White", "Percent Black",
"Percent Latine", "Percent Asian",
"Food Insecurity", "Marginal Food Insecurity"),
selected = "Percent White"),
# radio button to determine which food site type/options to display
shinyjs::useShinyjs(),
radioButtons("sites",
label = "Select which type of food site to display",
choices = c("Charitable food sites","Retailers"),
selected = "Charitable food sites",
inline = TRUE,
width = "1000px"),
conditionalPanel(
condition = "input.sites == 'Charitable food sites'",
## checkbox widget so user can select which criteria to visualize
checkboxGroupInput("eligibility",
label = "Select an eligibility type to display",
choices = c("No age restriction",
"Open to children only",
"Open to seniors only"),
selected = "No age restriction"),),
conditionalPanel(
condition = "input.sites == 'Retailers'",
checkboxGroupInput("retail",
label = "Select a retailer type to display",
choices = c("SNAP retailer" = "SNAP-retailer",
"Non-SNAP retailer" = "Non-SNAP retailer"),
selected = "Non-SNAP retailer"),),
),
mainPanel(
h1(textOutput("title"), align = "center"),
plotOutput("map")
)
)
)
# Server logic ----
server <- function(input, output, session) {
# Title for main panel
output$title <- renderText({
input$sites
})
## Constructing and storing data into a heat map
output$map <- renderPlot({
# The plotting function percent_map()
measure <- switch(input$sites,
"Charitable food sites" = "elig_type",
"Retailers" = "location_type")
if(input$sites == "Charitable food sites"){
eligibility_var <- %>%
filter(elig_type %in% c(input$eligibility))
limit <- c("No age restriction", "Open to children only",
"Open to seniors only")
colors <- c("#ec008b", "#fdbf11", "#000000")
}
if(input$sites == "Retailers"){
eligibility_var <- snap %>%
filter(location_type %in% c(input$retail))
limit <- c("SNAP retailers", "Non-SNAP retailers")
colors <- c("#ec008b", "#fdbf11")
}
race_var <- switch(input$var,
"Percent White" = "pct_nlwhite",
"Percent Black" = "pct_nlblack",
"Percent Latine" = "pct_latine",
"Percent Asian" = "pct_nlasian",
"Food Insecurity" = "FI",
"Marginal Food Insecurity" = "MFI")
## Switch to identify from the UI which legend title should be passed into
## the plotting function percent_map()
legend <- switch(input$var,
"Percent White" = "% White Population",
"Percent Black" = "% Black Population",
"Percent Latine" = "% Latine",
"Percent Hispanic" = "% Hispanic Population",
"Percent Asian" = "% Asian Population",
"Food Insecurity" = "% Food Insecurity",
"Marginal Food Insecurity" = "% Marginal Food Insecurity")
map_demographic(data1 = acs_ficombo,
data2 = eligibility_var,
site_display = measure,
percent_variable = race_var,
title1 = legend,
limit = limit,
colors = colors)
})
}
# Run app ----
shinyApp(ui = ui, server = server)