-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsite.R
executable file
·415 lines (402 loc) · 16.5 KB
/
site.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
library(community)
# use `page_` functions to add parts of a page
## `page_head` adds to the page's meta data, and can be a place to import script and style sheets
page_head(
title = "Virginia Department of Health Data Commons",
description = "Virginia Department of Health Data Commons.",
icon = "icon.svg"
)
## `page_header` adds to the top bar (navbar) of the page
page_navbar(
title = "Virginia Department of Health Data Commons",
logo = "icon.svg",
input_button("Reset", "reset_selection", "reset.selection", class = "btn-link", note = "Reset the menu inputs to their defaults."),
input_button("Filter", "filter", "open.filter", class = "btn-link"),
list(
name = "Settings",
backdrop = "false",
class = "menu-compact",
items = list(
input_switch("Dark Theme", id = "settings.theme_dark"),
input_select("Color Palette", options = "palettes", id = "settings.palette", floating_label = FALSE),
input_switch(
"Color by Rank", id = "settings.color_by_order",
note = paste(
"Switch from coloring by value to coloring by sorted index.",
"This may help differentiate regions with similar values."
)
),
input_switch("Hide URL Settings", id = "settings.hide_url_parameters"),
input_switch("Hide Tooltips", id = "settings.hide_tooltips"),
input_switch("Show Missing Years", id = "settings.show_empty_times"),
input_number("Digits", "settings.digits", default = 2, min = 0, max = 6, floating_label = FALSE),
input_select(
"Color Scale Center", options = c("none", "median", "mean"), default = "none",
display = c("None", "Median", "Mean"), id = "settings.color_scale_center",
floating_label = FALSE,
note = "Determines whether and on what the color scale should be centered."
),
input_select(
"Summary Level", options = c("dataset", "filtered", "children", "all"), default = "dataset",
display = c("All Regions", "Selected Region Types", "Selected Super-Region", "Showing Regions"), id = "settings.summary_selection",
floating_label = FALSE,
note = paste(
"Determines which regions are included in summaries for box-plots and color scaling;",
"All-Regions are state-wide, Selected Region Types are filtered by the Region Types input, and",
"Selected Region are filtered by region selection."
)
),
'<p class="section-heading">Map Options</p>',
input_switch("Show Overlay", default_on = TRUE, id = "settings.map_overlay"),
input_switch("Show Background Shapes", default_on = TRUE, id = "settings.background_shapes"),
input_switch("Background On Top", default_on = TRUE, id = "settings.background_top"),
input_select(
"Animations", c("fly", "zoom", "none"), "fly",
note = "Fly animates the whole move to different regions; Zoom only animates changes in zoom level.",
id = "settings.map_animations", floating_label = FALSE
),
input_number(
"Outline Weight", "settings.polygon_outline", default = 1.5, step = .5, floating_label = FALSE,
note = "Thickness of the outline around region shapes."
),
input_number(
"Background Outline Weight", "settings.background_polygon_outline", default = 2,
step = .5, floating_label = FALSE
),
input_number(
"Overlay Circle Size", "settings.circle_radius", default = 5, step = 1, floating_label = FALSE,
note = "Radius of the circles that are parts of overlays."
),
input_select(
"Overlay Circle Property", "overlay_properties", id = "settings.circle_property", floating_label = FALSE,
note = "Property to adjust circle size by."
),
'<p class="section-heading">Plot Options</p>',
input_select("Plot Type", c("scatter", "scattergl", "bar"), "scatter", id = "plot_type", floating_label = FALSE),
input_switch("Box Plots", default_on = TRUE, id = "settings.boxplots"),
input_switch(
"Use IQR Whiskers", default_on = TRUE, id = "settings.iqr_box",
note = "Define the extreme fences of the box plots by 1.5 * interquartile range (true) or min and max (false)."
),
input_number(
"Trace Limit", "settings.trace_limit", default = 20, floating_label = FALSE,
note = "Limit the number of plot traces that can be drawn, split between extremes of the variable."
),
'<p class="section-heading">Table Options</p>',
input_switch("Auto-Sort", default_on = TRUE, id = "settings.table_autosort"),
input_switch("Auto-Scroll", default_on = TRUE, id = "settings.table_autoscroll"),
input_select(
"Scroll Behavior", c("instant", "smooth", "auto"), "auto",
id = "settings.table_scroll_behavior", floating_label = FALSE
)
),
foot = list(
input_button("Clear Settings", "reset_storage", "clear_storage", class = "btn-danger")
)
),
list(
name = "About",
items = list(
page_text(c(
paste0(
"This site was made by the [Social and Decision Analytics Division]",
"(https://biocomplexity.virginia.edu/institute/divisions/social-and-decision-analytics)",
" of the [Biocomplexity Institute](https://biocomplexity.virginia.edu) for the ",
"[Virginia Department of Health](https://www.vdh.virginia.gov)."
),
"View its source on [GitHub](https://github.com/uva-bi-sdad/community_example).",
# input_button("Download Loaded Data", "export", query = list(
# features = list(geoid = "id", name = "name", region_type = "type")
# ), class = "btn-full"),
"Credits",
paste(
"Built in [R](https://www.r-project.org) with the",
"[community](https://uva-bi-sdad.github.io/community) package, using these resources:"
)
), class = c("", "", "h5")),
output_credits()
)
)
)
# use `input_` functions to add input elements that affect outputs
page_menu(
input_checkbox(
"Starting Layer", c("district", "county", "tract"), 1, c("Districts", "Counties", "Census Tracts"),
id = "starting_shapes", multi = FALSE, note = "Which geographies to show at the state level."
),
page_section(
type = "col",
wraps = "row form-row",
input_combobox(
"Health District", options = "ids", dataset = "district", dataview = "primary_view",
id = "selected_district", clearable = TRUE, note = paste(
"Health districts are sets of counties defined by the Virginia Department of Health."
)
),
input_combobox(
"County", options = "ids", dataset = "county", dataview = "primary_view",
id = "selected_county", selection_subset = "county_subset", clearable = TRUE
),
conditions = c("lock: !selected_county", "starting_shapes != district || selected_district")
),
input_checkbox(
"Region Types", options = c("rural", "mixed", "urban"), id = "region_type", as.switch = TRUE,
note = paste(
"Which region types to include. Types are defined at the county level, so only health districts",
"have mixed types, and all tracts are of the same type as their county."
)
),
page_section(
type = "col",
wraps = "row form-row",
input_combobox(
"Measure", options = "variables", group_feature = "category",
default = "incarceration_rate_per_100000", depends = "shapes",
id = "selected_variable", note = paste(
"Determines which variable is shown on the plot's y-axis, in the rank table,",
"and info fields, and used to color map polygons and plot elements."
)
)
),
position = "top",
default_open = TRUE,
sizes = c(1, NA, 1, NA)
)
## `input_variable` can be used to set up logical controls
input_variable("shapes", list(
"starting_shapes == district && !selected_district" = "district",
"starting_shapes == tract || selected_county" = "tract"
), "county")
input_variable("region_select", list(
"shapes == county" = "selected_county"
), "selected_district")
input_variable("selected_region", list(
"selected_county" = "selected_county"
), "selected_district")
input_variable("county_subset", list(
"selected_district" = "siblings"
), "full_filter")
## `input_dataview` can collect multiple inputs as filters for a shared data view
input_dataview(
"primary_view",
y = "selected_variable",
x = "selected_year",
dataset = "shapes",
ids = "selected_region",
features = c(type = "region_type"),
time_agg = "selected_year",
)
# use `page_section` to build the page's layout
page_section(
type = "col",
# use `output_` functions to add state and data displays
output_text(c(
"State: Virginia[r selected_county,selected_district]",
"? > Health District: {selected_district}[r selected_county]",
"? > {selected_county}"
), class = "compact"),
output_text(list(
"default" = "Virginia Counties",
"starting_shapes == tract" = "Virginia Census Tracts",
"starting_shapes == district" = "Virginia (Health Districts)[note: Sets of counties defined by the Virginia Department of Health.]",
"selected_district" = "{selected_district} Counties",
"selected_county" = "{selected_county} Census Tracts"
), tag = "h1", class = "text-center"),
page_section(
type = "container-xsm",
input_number(
"Selected Year", min = "filter.time_min", max = "filter.time_max", default = "max",
id = "selected_year", buttons = TRUE, show_range = TRUE, note = paste(
"Year of the selected variable to color the map shapes and plot elements by, and to show on hover."
)
)
),
page_section(
type = "row",
wraps = "col",
sizes = c(NA, 5),
output_map(
list(
list(
name = "tract",
time = 2010,
url = paste0(
"https://raw.githubusercontent.com/uva-bi-sdad/sdc.geographies/main/VA/Census%20Geographies/",
"Tract/2010/data/distribution/va_geo_census_cb_2010_census_tracts.geojson"
)
),
list(
name = "county",
time = 2010,
url = paste0(
"https://raw.githubusercontent.com/uva-bi-sdad/sdc.geographies/main/VA/Census%20Geographies/",
"County/2010/data/distribution/va_geo_census_cb_2010_counties.geojson"
)
),
list(
name = "tract",
time = 2020,
url = paste0(
"https://raw.githubusercontent.com/uva-bi-sdad/sdc.geographies/main/VA/Census%20Geographies/",
"Tract/2020/data/distribution/va_geo_census_cb_2020_census_tracts.geojson"
)
),
list(
name = "county",
time = 2020,
url = paste0(
"https://raw.githubusercontent.com/uva-bi-sdad/sdc.geographies/main/VA/Census%20Geographies/",
"County/2020/data/distribution/va_geo_census_cb_2020_counties.geojson"
)
),
list(
name = "district",
url = paste0(
"https://raw.githubusercontent.com/uva-bi-sdad/sdc.geographies/main/VA/State%20Geographies/Health%20Districts/",
"2020/data/distribution/va_geo_vhd_2020_health_districts.geojson"
)
)
),
dataview = "primary_view",
click = "region_select",
id = "main_map",
subto = c("main_plot", "rank_table", "main_legend"),
options = list(
attributionControl = FALSE,
scrollWheelZoom = FALSE,
center = c(38, -79.5),
zoom = 7,
height = "430px",
zoomAnimation = "settings.map_zoom_animation"
),
background_shapes = "county",
tiles = list(
light = list(url = "https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png"),
dark = list(url = "https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png")
),
attribution = list(
list(
name = "Stamen toner-light",
url = "https://stamen.com",
description = "Light-theme map tiles by Stamen Design"
),
list(
name = "CARTO Dark Matter",
url = "https://carto.com/attributions",
description = "Dark-theme map tiles by CARTO"
),
list(
name = "OpenStreetMap",
url = "https://www.openstreetmap.org/copyright"
)
)
),
page_section(
type = "flex-column col",
## use `output_info` to display information about selected and hovered-over entities
output_info(
dataview = "primary_view",
id = "variable_info_pane",
),
'
<script async src="https://www.googletagmanager.com/gtag/js?id=G-278827H8WK"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag("js", new Date());
gtag("config", "G-278827H8WK");
</script>
<script>
function download_variable(){
var urlParams = new URLSearchParams(window.location.search);
let selectedVar = urlParams.get("selected_variable");
if (selectedVar == null){
selectedVar = "incarceration_rate_per_100000"; // The default starting variable name for this repository
}
window.location = "https://github.com/uva-bi-sdad/sdc.measures/raw/main/"+ selectedVar + ".csv.xz";
gtag("event", "file_download", {
"measure": selectedVar
});
}
</script>
<button onclick="download_variable()" id= "download_variable_button" type="button" class="btn popup-button mb-2">Download All</button>
',
page_popup(
"Download Filtered",
page_section(
wraps = "col",
input_select("Table Format", c("tall", "mixed", "wide"), "mixed", id = "export_table_format"),
input_select("File Format", c("csv", "tsv"), "csv", c("CSV", "TSV"), id = "export_file_format")
),
input_button(
"Download", "export", dataview = "primary_view", query = list(
include = "selected_variable",
features = list(geoid = "id", name = "name"),
table_format = "export_table_format", file_format = "export_file_format"
), class = "btn-full"
),
input_button(
"Copy API link", "copy", dataview = "primary_view", query = list(
include = "selected_variable", dataset = "shapes",
features = list(geoid = "id", name = "name"),
table_format = "export_table_format", file_format = "export_file_format"
), class = "btn-full"
)
),
output_info(body = "summary", dataview = "primary_view"),
output_info("Filters", "filter", dataview = "primary_view"),
page_section(
output_info(
title = "features.name",
default = c(title = "Virginia", body = "Hover over or select a region for more information."),
dataview = "primary_view",
subto = c("main_map", "main_plot", "rank_table", "main_legend")
),
output_info(
body = c(
"Region Type" = "features.type",
"variables.long_name" = "selected_variable",
"variables.statement"
),
row_style = c("table", "stack"),
dataview = "primary_view",
subto = c("main_map", "main_plot", "rank_table", "main_legend"),
variable_info = FALSE
)
)
)
),
page_section(
type = "row",
wraps = "col",
sizes = c(5, 7),
page_section(
output_legend(
"settings.palette", dataview = "primary_view", click = "region_select",
subto = c("main_map", "main_plot", "rank_table"), id = "main_legend"
),
output_table("selected_variable", dataview = "primary_view", options = list(
info = FALSE,
searching = FALSE,
scrollY = 300,
dom = "<'row't>"
), id = "rank_table", click = "region_select", subto = c("main_map", "main_plot", "main_legend"))
),
output_plot(
x = "time", y = "selected_variable", dataview = "primary_view",
click = "region_select", subto = c("main_map", "rank_table", "main_legend"), id = "main_plot",
options = list(
layout = list(
xaxis = list(title = FALSE, fixedrange = TRUE),
yaxis = list(fixedrange = TRUE, zeroline = FALSE)
),
data = data.frame(
type = c("plot_type", "box"), fillcolor = c(NA, "transparent"),
hoverinfo = c("text", NA), mode = "lines+markers", showlegend = FALSE,
name = c(NA, "Summary"), marker.line.color = "#767676", marker.line.width = 1
),
config = list(modeBarButtonsToRemove = c("select2d", "lasso2d", "sendDataToCloud"))
)
)
)
)