-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
261 lines (231 loc) · 11.9 KB
/
server.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# COHHIO_HMIS
# Copyright (C) 2020 Coalition on Homelessness and Housing in Ohio (COHHIO)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details at
# <https://www.gnu.org/licenses/>.
shinyServer(function(input, output) {
output$aboutText <- renderUI({
HTML(
"<p>This tool was built by COHHIO and is using the data from the Urban
Institute's
<a href = \"https://www.urban.org/features/where-prioritize-emergency-rental-assistance-keep-renters-their-homes\">ERA Prioritization Tool</a>.
The Ohio Balance of State CoC is incorporating the Indices into our
targeting and prioritization process for our Homelessness Prevention and
Emergency Rental Assistance projects. We needed our case managers to be able
to find the Index for a specific household in a very user-friendly way.</p>
<p>Of course any CoC in the US may use this tool as it includes the data
from each state. We plan to maintain it until there is something better or
it is not needed by anyone. The code for this Shiny app is available
<a href = \"https://github.com/COHHIO/hpgeotool\">here</a>.
<p>For more information about incorporating Racial Equity into the
implementation of your ESG-CV dollars, please visit
<a href =\"https://housingequityframework.org/\">housingequityframework.org</a>."
)})
output$citationsText <- renderUI({
HTML(
"<p>Urban Institute. 2021 Rental Assistance Priority Index.
Accessible from
<a href = \"https://datacatalog.urban.org/dataset/rental-assistance-priority-index\">here</a>.
Data originally sourced from 2015-19 ACS, March 2021 update of the Urban
Institute’s “Where Low-Income Jobs Are Being Lost to COVID-19” data tool,
and the 2013–17 US Department of Housing and Urban Developments
Comprehensive Housing Affordability Strategy data. Developed at the
Urban Institute, and made available under the ODC-BY 1.0 Attribution
License.</p>
<p>Wickham et al., (2019). Welcome to the
<a href=\"https://doi.org/10.21105/joss.01686\">tidyverse</a>. Journal
of Open Source Software, 4(43), 1686</p>
<p>Winston Chang, Joe Cheng, JJ Allaire, Yihui Xie and Jonathan McPherson
(2020). <a href=\"https://CRAN.R-project.org/package=shiny\">shiny</a>:
Web Application Framework for R. R package version 1.5.0. </p>
<p>Winston Chang and Barbara Borges Ribeiro (2018).
<a href=\"https://CRAN.R-project.org/package=shinydashboard\">shinydashboard</a>:
Create Dashboards with 'Shiny'. R package version 0.7.1. </p>
<p>Jesse Cambon (2020). <a href=\"https://CRAN.R-project.org/package=tidygeocoder\">tidygeocoder</a>:
Geocoding Made Easy. R package version 1.0.1.</p>
<p>Please send inquiries to the <a href = \"mailto:[email protected].\">COHHIO HMIS team</a>."
)})
observeEvent(input$go, {
address <- reactive(tibble(singlelineaddress = c(input$address)))
withProgress(message = "Looking for your address", {
one_observation <- nrow(
census_full <-
address() %>%
geocode(
address = singlelineaddress,
method = 'census',
full_results = TRUE,
api_options = list(census_return_type = 'geographies')
)
) == 1
lat_valid <- !is.na(census_full$lat[1])
status <- case_when(
one_observation == FALSE ~ "insufficient",
one_observation == TRUE &
lat_valid == TRUE ~ "good",
one_observation == TRUE &
lat_valid == FALSE ~ "bad",
TRUE ~ "contact administrator"
)
# if the address is "bad", the census blocks can't be unnested
if (status != "bad") {
census <-
census_full %>%
unnest('geographies.2020 Census Blocks') %>%
mutate(GEOID = substr(GEOID, 1, 11))
}
the_geocode <-
reactive(census %>% pull(GEOID))
your_state <- reactive(index %>%
filter(GEOID == the_geocode()) %>%
pull(state_name))
output$Indices <- renderUI({
if (status == "good") {
list(
infoBox(
subtitle = paste("Within", your_state()),
title = "Total Index",
index %>%
filter(GEOID == the_geocode()) %>%
pull(total_index_quantile),
icon = icon("location-dot"),
color = "black",
width = 12
),
infoBox(
subtitle = paste("Within", your_state()),
title = "Housing Index",
index %>%
filter(GEOID == the_geocode()) %>%
pull(housing_index_quantile),
icon = icon("house-user")
),
infoBox(
subtitle = paste("Within", your_state()),
title = "COVID Index",
index %>%
filter(GEOID == the_geocode()) %>%
pull(covid_index_quantile),
icon = icon("virus")
),
infoBox(
subtitle = paste("Within", your_state()),
title = "Equity Index",
index %>%
filter(GEOID == the_geocode()) %>%
pull(equity_index_quantile),
icon = icon("scale-unbalanced")
)
)
} else{
}
})
output$Insufficient <- renderUI({
if (status == "insufficient") {
difference <- function(x)
length(unique(x)) > 1
address_check <- census %>%
select(starts_with("addressComponents")) %>%
map_dbl(difference)
to_check <-
names(address_check)[address_check == 1]
friendly_names <- case_when(
to_check == "addressComponents.preQualifier" ~
"Pre-Qualifier, like \"Old\", \"New\"",
to_check == "addressComponents.preDirection" ~
"Direction, like \"North\", \"SW\"",
to_check == "addressComponents.preType" ~
"Type, like \"Route\", \"US HWY\", or \"Via\"",
to_check == "addressComponents.streetName" ~
"Street",
to_check == "addressComponents.suffixType" ~
"Suffix, like \"Street\" or \"Blvd\"",
to_check == "addressComponents.suffixDirection" ~
"Direction, like \"North\", \"SW\"",
to_check == "addressComponents.suffixQualifier" ~
"Post-Qualifier, like \"Bypass\", \"Private\"",
to_check == "addressComponents.city" ~
"City",
to_check == "addressComponents.state" ~
"State",
to_check == "addressComponents.zip" ~
"ZIP"
)
insufficient_address <-
paste("Please check your",
paste(friendly_names,
collapse = " & "))
infoBox(
title = "Error",
subtitle = print(insufficient_address),
icon = icon("xmark"),
color = "orange",
width = 12
)
} else{
}
})
output$Garbage <- renderUI({
if (status == "bad") {
infoBox(
title = "NO MATCH",
subtitle = "Check your address and try again.",
icon = icon("xmark"),
color = "fuchsia",
width = 12
)
} else{
}
})
output$Interpret <- renderUI({
if(status == "good")
HTML(paste(
"PLEASE NOTE: The Rental Assistance Priority Index and its
subindexes are built on historical census data and estimates
that may not capture the current need in each neighborhood. We
recommend using this tool in conjunction with a community-based
process that includes examining local homelessness data and
engaging stakeholders from groups and neighborhoods that local
data show are disproportionately represented in evictions,
homelessness, and COVID-19 infection and mortality. The higher
the percentile, the higher the priority.<p><p>",
"The address entered is in census tract",
the_geocode(),
". This census tract's Rental Assistance Priority Index is",
index %>%
filter(GEOID == the_geocode()) %>%
pull(total_index_quantile) %>%
as.character(),
". This index is comprised of three subindexes:<p>
<ul><li>The Housing Index</li>
<li>The Covid Index</li>
<li>The Equity Index</li></ul>
<p>The census tract your address is located in has a Housing
Index of",
index %>%
filter(GEOID == the_geocode()) %>%
pull(housing_index_quantile),
". This index represents the extent to which renters in your
census tract are living in poverty, are severely cost-burdened
and low-income, whose annual incomes are less than $35,000 and
pay 50 percent or more of their incomes in gross rent, the area
has a higher percent of renter-occupied housing units,
severely overcrowded households: percentage of renter-occupied households with more
than 1.5 occupants per room Share of unemployed people"
))
})
{
incProgress(1 / 2)
}
})
},
ignoreInit = TRUE)
})