forked from eparker12/nCoV_tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
512 lines (512 loc) · 28.5 KB
/
.Rhistory
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
sars_final_case_count = sum(sars_final$cases)
# select polygons for sars base map
sars_large_countries = sars_final %>% filter(country %in% country_geoms$countries_present)
sars_large_countries = sars_large_countries[order(sars_large_countries$alpha3),]
sars_plot_map <- worldcountry[worldcountry$ADM0_A3 %in% sars_large_countries$alpha3, ]
# create plotting parameters for sars map
sars_pal <- colorBin("Blues", domain = sars_large_countries$permill, bins = bins)
# creat sars interactive map (needs to include polygons and circles as slider input not recognised upon initial loading)
sars_basemap = leaflet(sars_plot_map) %>%
addTiles() %>%
addLayersControl(
position = "bottomright",
overlayGroups = c("2003-SARS (cumulative)", "2019-COVID", "2009-H1N1 (swine flu)", "2014-Ebola"),
options = layersControlOptions(collapsed = FALSE)) %>%
hideGroup(c("2019-COVID", "2009-H1N1 (swine flu)", "2014-Ebola")) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
fitBounds(~-100,-60,~60,70) %>%
addPolygons(stroke = FALSE, smoothFactor = 0.2, fillOpacity = 0.4, fillColor = ~sars_pal(sars_large_countries$permill), group = "2003-SARS (cumulative)",
label = sprintf("<strong>%s</strong><br/>SARS cases: %g<br/>Deaths: %d<br/>Cases per million: %g", sars_large_countries$country, sars_large_countries$cases, sars_large_countries$deaths, sars_large_countries$permill) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = sars_col),
textsize = "15px", direction = "auto")) %>%
addCircleMarkers(data = sars_final, lat = ~ latitude, lng = ~ longitude, weight = 1, radius = ~(cases)^(1/4),
fillOpacity = 0.2, color = sars_col, group = "2003-SARS (cumulative)",
label = sprintf("<strong>%s</strong><br/>SARS cases: %g<br/>Deaths: %d<br/>Cases per million: %g", sars_final$country, sars_final$cases, sars_final$deaths, sars_final$permill) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = sars_col),
textsize = "15px", direction = "auto")) %>%
addCircleMarkers(data = cv_today, lat = ~ latitude, lng = ~ longitude, weight = 1, radius = ~(cases)^(1/5.5),
fillOpacity = 0.2, color = covid_col, group = "2019-COVID",
label = sprintf("<strong>%s (cumulative)</strong><br/>Confirmed cases: %g<br/>Deaths: %d<br/>Cases per million: %g", cv_today$country, cv_today$cases, cv_today$deaths, cv_today$permill) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = covid_col),
textsize = "15px", direction = "auto")) %>%
addCircleMarkers(data = h1n1_cases, lat = ~ latitude, lng = ~ longitude, weight = 1, radius = ~(projected_deaths)^(1/4),
fillOpacity = 0.2, color = h1n1_col, group = "2009-H1N1 (swine flu)",
label = sprintf("<strong>%s</strong><br/>H1N1 deaths (confirmed): %g<br/>H1N1 deaths (estimated): %g", h1n1_cases$region, h1n1_cases$deaths, h1n1_cases$projected_deaths) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = h1n1_col),
textsize = "15px", direction = "auto")) %>%
addCircleMarkers(data = ebola_cases, lat = ~ latitude, lng = ~ longitude, weight = 1, radius = ~(cases)^(1/4),
fillOpacity = 0.2, color = ebola_col, group = "2014-Ebola",
label = sprintf("<strong>%s</strong><br/>Ebola cases: %g<br/>Deaths: %d", ebola_cases$country, ebola_cases$cases, ebola_cases$deaths) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = ebola_col),
textsize = "15px", direction = "auto"))
# sum sars case counts by date
sars_aggregated = aggregate(sars_cases$cases, by=list(Category=sars_cases$date), FUN=sum)
names(sars_aggregated) = c("date", "cases")
# add variable for new sars cases in last 7 days
for (i in 1:nrow(sars_aggregated)) {
if (i==1) { sars_aggregated$new[i] = NA }
if (i>1) {
sars_aggregated$new[i] = sars_aggregated$cases[i] - sars_aggregated$cases[i-1]
}
}
sars_aggregated$new[sars_aggregated$new<0] = 0
### OUTBREAK COMPARISON DATA ###
# load epidemic comparison data
epi_comp = as.data.frame(data.table::fread("input_data/epi_comp.csv"))
epi_comp$outbreak = factor(epi_comp$outbreak, levels = epi_comp$outbreak)
epi_comp$cases[1] = current_case_count
epi_comp$deaths[1] = current_death_count
epi_comp$countries[1] = nrow(subset(cv_today, country!="Diamond Princess Cruise Ship"))
epi_comp$cfr[1] = round(epi_comp$deaths[1]/epi_comp$cases[1]*100,1)
epi_comp$cfr = round(epi_comp$cfr,2)
### SHINY UI ###
ui <- bootstrapPage(
tags$head(includeHTML("gtag.html")),
navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
HTML('<a style="text-decoration:none;cursor:default;color:#FFFFFF;" class="active" href="#">COVID-19 tracker</a>'), id="nav",
windowTitle = "COVID-19 tracker",
tabPanel("COVID-19 mapper",
div(class="outer",
tags$head(includeCSS("styles.css")),
leafletOutput("mymap", width="100%", height="100%"),
absolutePanel(id = "controls", class = "panel panel-default",
top = 75, left = 55, width = 250, fixed=TRUE,
draggable = TRUE, height = "auto",
span(tags$i(h6("Reported cases are subject to significant variation in testing policy and capacity between countries.")), style="color:#045a8d"),
h3(textOutput("reactive_case_count"), align = "right"),
h4(textOutput("reactive_death_count"), align = "right"),
h6(textOutput("clean_date_reactive"), align = "right"),
h6(textOutput("reactive_country_count"), align = "right"),
plotOutput("epi_curve", height="130px", width="100%"),
plotOutput("cumulative_plot", height="130px", width="100%"),
sliderTextInput("plot_date",
label = h5("Select mapping date"),
choices = format(unique(cv_cases$date), "%d %b %y"),
selected = format(current_date, "%d %b %y"),
grid = FALSE,
animate=animationOptions(interval = 3000, loop = FALSE))
),
absolutePanel(id = "logo", class = "card", bottom = 20, left = 60, width = 80, fixed=TRUE, draggable = FALSE, height = "auto",
tags$a(href='https://www.lshtm.ac.uk', tags$img(src='lshtm_dark.png',height='40',width='80'))),
absolutePanel(id = "logo", class = "card", bottom = 20, left = 20, width = 30, fixed=TRUE, draggable = FALSE, height = "auto",
actionButton("twitter_share", label = "", icon = icon("twitter"),style='padding:5px',
onclick = sprintf("window.open('%s')",
"https://twitter.com/intent/tweet?text=%20@LSHTM_Vaccines%20outbreak%20mapper&url=https://bit.ly/2uBvnds&hashtags=coronavirus")))
)
),
tabPanel("Region plots",
sidebarLayout(
sidebarPanel(
span(tags$i(h6("Reported cases are subject to significant variation in testing policy and capacity between countries.")), style="color:#045a8d"),
span(tags$i(h6("Occasional anomalies (e.g. spikes in daily case counts) are generally caused by changes in case definitions.")), style="color:#045a8d"),
pickerInput("level_select", "Level:",
choices = c("Global", "Continent", "Country", "US state"),
selected = c("Country"),
multiple = FALSE),
pickerInput("region_select", "Country/Region:",
choices = as.character(cv_today_reduced[order(-cv_today_reduced$cases),]$country),
options = list(`actions-box` = TRUE, `none-selected-text` = "Please make a selection!"),
selected = as.character(cv_today_reduced[order(-cv_today_reduced$cases),]$country)[1:10],
multiple = TRUE),
pickerInput("outcome_select", "Outcome:",
choices = c("Deaths per million", "Cases per million", "Cases (total)", "Deaths (total)"),
selected = c("Deaths per million"),
multiple = FALSE),
pickerInput("start_date", "Plotting start date:",
choices = c("Date", "Day of 100th confirmed case", "Day of 10th death"),
options = list(`actions-box` = TRUE),
selected = "Date",
multiple = FALSE),
sliderInput("minimum_date",
"Minimum date:",
min = as.Date(cv_min_date,"%Y-%m-%d"),
max = as.Date(current_date,"%Y-%m-%d"),
value=as.Date(cv_min_date),
timeFormat="%d %b"),
"Select outcome, regions, and plotting start date from drop-down menues to update plots. Countries with at least 1000 confirmed cases are included."
),
mainPanel(
tabsetPanel(
tabPanel("Cumulative", plotlyOutput("country_plot_cumulative")),
tabPanel("New", plotlyOutput("country_plot")),
tabPanel("Cumulative (log10)", plotlyOutput("country_plot_cumulative_log"))
)
)
)
),
tabPanel("SARS mapper",
div(class="outer",
tags$head(includeCSS("styles.css")),
leafletOutput("sars_map", width="100%", height="100%"),
absolutePanel(id = "controls", class = "panel panel-default",
top = 75, left = 55, width = 250, fixed=TRUE,
draggable = TRUE, height = "auto",
h3(textOutput("sars_reactive_case_count"), align = "right"),
h4(textOutput("sars_reactive_death_count"), align = "right"),
h6(textOutput("sars_clean_date_reactive"), align = "right"),
h6(textOutput("sars_reactive_country_count"), align = "right"),
plotOutput("sars_epi_curve", height="130px", width="100%"),
plotOutput("sars_cumulative_plot", height="130px", width="100%"),
span(("The final count appears to decrease as several cases initially classified as SARS were later re-assigned."),align = "left", style = "font-size:80%"),#tags$br(),
span(("Circles show confirmed cases for COVID, SARS, and Ebola, and estimated deaths for H1N1."),align = "left", style = "font-size:80%"),
sliderTextInput("sars_plot_date",
label = h5("Select mapping date"),
choices = format(unique(sars_cases$date), "%d %b %y"),
selected = format(sars_max_date, "%d %b %y"),
grid = FALSE,
animate=animationOptions(interval = 3000, loop = FALSE))
),
absolutePanel(id = "logo", class = "card", bottom = 15, left = 60, width = 80, fixed=TRUE, draggable = FALSE, height = "auto",
tags$a(href='https://www.lshtm.ac.uk', tags$img(src='lshtm_dark.png',height='40',width='80'))),
absolutePanel(id = "logo", class = "card", bottom = 15, left = 20, width = 30, fixed=TRUE, draggable = FALSE, height = "auto",
actionButton("twitter_share", label = "", icon = icon("twitter"),style='padding:5px',
onclick = sprintf("window.open('%s')",
"https://twitter.com/intent/tweet?text=%20@LSHTM_Vaccines%20outbreak%20mapper&url=https://bit.ly/2uBvnds&hashtags=coronavirus")))
)
),
tabPanel("Outbreak comparisons",
sidebarLayout(
sidebarPanel(
radioButtons("comparison_metric", h3("Select comparison:"),
c("Cases" = "cases",
"Deaths" = "deaths",
"Countries/regions affected" = "countries",
"Case fatality rate" = "cfr")),
textOutput("epi_notes_1"),
textOutput("epi_notes_2"),
textOutput("epi_notes_3")
),
mainPanel(plotlyOutput("comparison_plot"), width = 6)
)
),
tabPanel("Data",
numericInput("maxrows", "Rows to show", 25),
verbatimTextOutput("rawtable"),
downloadButton("downloadCsv", "Download as CSV"),tags$br(),tags$br(),
"Adapted from timeline data published by ", tags$a(href="https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data/csse_covid_19_time_series",
"Johns Hopkins Center for Systems Science and Engineering.")
),
tabPanel("About this site",
tags$div(
tags$h4("Last update"),
h6(paste0(update)),
"This site is updated once daily. There are several other excellent COVID mapping tools available, including those run by",
tags$a(href="https://experience.arcgis.com/experience/685d0ace521648f8a5beeeee1b9125cd", "the WHO,"),
tags$a(href="https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6", "Johns Hopkins University,"),"and",
tags$a(href="https://ourworldindata.org/coronavirus-data-explorer?zoomToSelection=true&time=2020-03-01..latest&country=IND~USA~GBR~CAN~DEU~FRA®ion=World&casesMetric=true&interval=smoothed&perCapita=true&smoothing=7&pickerMetric=total_cases&pickerSort=desc", "Our World in Data."),
"Our aim is to complement these resources with several interactive features, including the timeline function and the ability to overlay past outbreaks.",
tags$br(),tags$br(),tags$h4("Background"),
"In December 2019, cases of severe respiratory illness began to be reported across the city of Wuhan in China.
These were caused by a new type of coronavirus, and the disease is now commonly referred to as COVID-19.
The number of COVID-19 cases started to escalate more quickly in mid-January and the virus soon spread beyond China's borders.
This story has been rapidly evolving ever since, and each day we are faced by worrying headlines regarding the current state of the outbreak.",
tags$br(),tags$br(),
"In isolation, these headlines can be hard to interpret.
How fast is the virus spreading? Are efforts to control the disease working? How does the situation compare with previous epidemics?
This site is updated daily based on data published by Johns Hopkins University.
By looking beyond the headlines, we hope it is possible to get a deeper understanding of this unfolding pandemic.",
tags$br(),tags$br(),
"An article discussing this site was published in ",tags$a(href="https://theconversation.com/coronavirus-outbreak-a-new-mapping-tool-that-lets-you-scroll-through-timeline-131422", "The Conversation. "),
"The map was also featured on the BBC World Service program",tags$a(href="https://www.bbc.co.uk/programmes/w3csym33", "Science in Action."),
tags$br(),tags$br(),tags$h4("Code"),
"Code and input data used to generate this Shiny mapping tool are available on ",tags$a(href="https://github.com/eparker12/nCoV_tracker", "Github."),
tags$br(),tags$br(),tags$h4("Sources"),
tags$b("2019-COVID cases: "), tags$a(href="https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data/csse_covid_19_time_series", "Johns Hopkins Center for Systems Science and Engineering github page,")," with additional information from the ",tags$a(href="https://www.who.int/emergencies/diseases/novel-coronavirus-2019/situation-reports", "WHO's COVID-19 situation reports."),
" In previous versions of this site (up to 17th March 2020), updates were based solely on the WHO's situation reports.",tags$br(),
tags$b("US state-level case data: "), tags$a(href="https://github.com/nytimes/covid-19-data", "New York Times github page,"),
tags$b("2003-SARS cases: "), tags$a(href="https://www.who.int/csr/sars/country/en/", "WHO situation reports"),tags$br(),
tags$b("2009-H1N1 confirmed deaths: "), tags$a(href="https://www.who.int/csr/disease/swineflu/updates/en/", "WHO situation reports"),tags$br(),
tags$b("2009-H1N1 projected deaths: "), "Model estimates from ", tags$a(href="https://journals.plos.org/plosmedicine/article?id=10.1371/journal.pmed.1001558", "GLaMOR Project"),tags$br(),
tags$b("2009-H1N1 cases: "), tags$a(href="https://www.cdc.gov/flu/pandemic-resources/2009-h1n1-pandemic.html", "CDC"),tags$br(),
tags$b("2009-H1N1 case fatality rate: "), "a systematic review by ", tags$a(href="https://www.ncbi.nlm.nih.gov/pubmed/24045719", "Wong et al (2009)"), "identified
substantial variation in case fatality rate estimates for the H1N1 pandemic. However, most were in the range of 10 to 100 per 100,000 symptomatic cases (0.01 to 0.1%).
The upper limit of this range is used for illustrative purposes in the Outbreak comarisons tab.",tags$br(),
tags$b("2014-Ebola cases: "), tags$a(href="https://www.cdc.gov/flu/pandemic-resources/2009-h1n1-pandemic.html", "CDC"),tags$br(),
tags$b("Country mapping coordinates: "), tags$a(href="https://github.com/martynafford/natural-earth-geojson", "Martyn Afford's Github repository"),
tags$br(),tags$br(),tags$h4("Authors"),
"Dr Edward Parker, The Vaccine Centre, London School of Hygiene & Tropical Medicine",tags$br(),
"Quentin Leclerc, Department of Infectious Disease Epidemiology, London School of Hygiene & Tropical Medicine",tags$br(),
tags$br(),tags$br(),tags$h4("Contact"),
"[email protected]",tags$br(),tags$br(),
tags$img(src = "vac_dark.png", width = "150px", height = "75px"), tags$img(src = "lshtm_dark.png", width = "150px", height = "75px")
)
)
)
)
### SHINY SERVER ###
server = function(input, output, session) {
# covid tab
formatted_date = reactive({
format(as.Date(input$plot_date, format="%d %b %y"), "%Y-%m-%d")
})
output$clean_date_reactive <- renderText({
format(as.POSIXct(formatted_date()),"%d %B %Y")
})
reactive_db = reactive({
cv_cases %>% filter(date == formatted_date())
})
reactive_db_last7d = reactive({
cv_cases %>% filter(date == formatted_date() & new_cases>0)
})
reactive_db_large = reactive({
large_countries = reactive_db() %>% filter(alpha3 %in% worldcountry$ADM0_A3)
#large_countries = reactive %>% filter(alpha3 %in% worldcountry$ADM0_A3)
worldcountry_subset = worldcountry[worldcountry$ADM0_A3 %in% large_countries$alpha3, ]
large_countries = large_countries[match(worldcountry_subset$ADM0_A3, large_countries$alpha3),]
large_countries
})
reactive_db_large_last7d = reactive({
large_countries = reactive_db_last7d() %>% filter(alpha3 %in% worldcountry$ADM0_A3)
large_countries = large_countries[order(large_countries$alpha3),]
large_countries
})
reactive_polygons = reactive({
worldcountry[worldcountry$ADM0_A3 %in% reactive_db_large()$alpha3, ]
})
reactive_polygons_last7d = reactive({
worldcountry[worldcountry$ADM0_A3 %in% reactive_db_large_last7d()$alpha3, ]
})
output$reactive_case_count <- renderText({
paste0(prettyNum(sum(reactive_db()$cases), big.mark=","), " cases")
})
output$reactive_death_count <- renderText({
paste0(prettyNum(sum(reactive_db()$deaths), big.mark=","), " deaths")
})
output$reactive_country_count <- renderText({
paste0(nrow(subset(reactive_db(), country!="Diamond Princess Cruise Ship")), " countries/regions affected")
})
output$reactive_new_cases_7d <- renderText({
paste0(round((cv_aggregated %>% filter(date == formatted_date() & region=="Global"))$new/7,0), " 7-day average")
})
output$mymap <- renderLeaflet({
basemap
})
observeEvent(input$plot_date, {
leafletProxy("mymap") %>%
clearMarkers() %>%
clearShapes() %>%
addCircleMarkers(data = reactive_db(), lat = ~ latitude, lng = ~ longitude, weight = 1, radius = ~(cases)^(1/5.5),
fillOpacity = 0.1, color = covid_col, group = "2019-COVID (cumulative)",
label = sprintf("<strong>%s (cumulative)</strong><br/>Confirmed cases: %g<br/>Deaths: %d<br/>Cases per million: %g<br/>Deaths per million: %g", reactive_db()$country, reactive_db()$cases, reactive_db()$deaths, reactive_db()$permill, reactive_db()$deathspermill) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = covid_col),
textsize = "15px", direction = "auto")) %>%
addPolygons(data = reactive_polygons(), stroke = FALSE, smoothFactor = 0.1, fillOpacity = 0.15, fillColor = ~cv_pal(reactive_db_large()$deathspermill)) %>%
addCircleMarkers(data = reactive_db_last7d(), lat = ~ latitude, lng = ~ longitude, weight = 1, radius = ~(new_cases)^(1/5.5),
fillOpacity = 0.1, color = covid_col, group = "2019-COVID (new)",
label = sprintf("<strong>%s (7-day average)</strong><br/>Confirmed cases: %g<br/>Deaths: %d<br/>Cases per million: %g<br/>Deaths per million: %g", reactive_db_last7d()$country, round(reactive_db_last7d()$new_cases/7,0), round(reactive_db_last7d()$new_deaths/7,0), round(reactive_db_last7d()$newpermill/7,1), round(reactive_db_last7d()$newdeathspermill/7,1)) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = covid_col),
textsize = "15px", direction = "auto")) %>%
addCircleMarkers(data = sars_final, lat = ~ latitude, lng = ~ longitude, weight = 1, radius = ~(cases)^(1/4),
fillOpacity = 0.2, color = sars_col, group = "2003-SARS",
label = sprintf("<strong>%s</strong><br/>SARS cases: %g<br/>Deaths: %d<br/>Cases per million: %g", sars_final$country, sars_final$cases, sars_final$deaths, sars_final$permill) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = sars_col),
textsize = "15px", direction = "auto")) %>%
addCircleMarkers(data = h1n1_cases, lat = ~ latitude, lng = ~ longitude, weight = 1, radius = ~(projected_deaths)^(1/4),
fillOpacity = 0.2, color = h1n1_col, group = "2009-H1N1 (swine flu)",
label = sprintf("<strong>%s</strong><br/>H1N1 deaths (confirmed): %g<br/>H1N1 deaths (estimated): %g", h1n1_cases$region, h1n1_cases$deaths, h1n1_cases$projected_deaths) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = h1n1_col),
textsize = "15px", direction = "auto")) %>%
addCircleMarkers(data = ebola_cases, lat = ~ latitude, lng = ~ longitude, weight = 1, radius = ~(cases)^(1/4),
fillOpacity = 0.2, color = ebola_col, group = "2014-Ebola",
label = sprintf("<strong>%s</strong><br/>Ebola cases: %g<br/>Deaths: %d", ebola_cases$country, ebola_cases$cases, ebola_cases$deaths) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = ebola_col),
textsize = "15px", direction = "auto"))
})
output$cumulative_plot <- renderPlot({
cumulative_plot(cv_aggregated, formatted_date())
})
output$epi_curve <- renderPlot({
new_cases_plot(cv_aggregated, formatted_date())
})
# sars tab
sars_mod_date = reactive({
format(as.Date(input$sars_plot_date, format="%d %b %y"), "%Y-%m-%d")
})
output$sars_clean_date_reactive <- renderText({
format(as.POSIXct(sars_mod_date()),"%d %B %Y")
})
sars_reactive_db = reactive({
sars_cases %>% filter(date == sars_mod_date())
})
sars_reactive_db_large = reactive({
large_countries = sars_reactive_db() %>% filter(country!="Singapore" & country!="Diamond Princess Cruise Ship" & country!="Hong Kong" & country!="Macao")
large_countries = large_countries[order(large_countries$alpha3),]
large_countries
})
sars_reactive_polygons = reactive({
worldcountry[worldcountry$ADM0_A3 %in% sars_reactive_db_large()$alpha3, ]
})
output$sars_reactive_case_count <- renderText({
paste0(sum(sars_reactive_db()$cases), " cases")
})
output$sars_reactive_death_count <- renderText({
paste0(sum(sars_reactive_db()$deaths), " deaths")
})
output$sars_reactive_country_count <- renderText({
paste0(length(unique(sars_reactive_db()$country_group)), " countries/territories affected")
})
output$sars_map <- renderLeaflet({
sars_basemap
})
observeEvent(input$sars_plot_date, {
leafletProxy("sars_map") %>%
clearMarkers() %>%
clearShapes() %>%
addPolygons(data = sars_reactive_polygons(), stroke = FALSE, smoothFactor = 0.2, fillOpacity = 0.1, fillColor = ~sars_pal(sars_reactive_db_large()$permill), group = "2003-SARS (cumulative)",
label = sprintf("<strong>%s</strong><br/>SARS cases: %g<br/>Deaths: %d<br/>Cases per million: %g", sars_reactive_db_large()$country, sars_reactive_db_large()$cases, sars_reactive_db_large()$deaths, sars_reactive_db_large()$permill) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = sars_col),
textsize = "15px", direction = "auto")) %>%
addCircleMarkers(data = sars_reactive_db(), lat = ~ latitude, lng = ~ longitude, weight = 1, radius = ~(cases)^(1/4),
fillOpacity = 0.2, color = sars_col, group = "2003-SARS (cumulative)",
label = sprintf("<strong>%s</strong><br/>SARS cases: %g<br/>Deaths: %d<br/>Cases per million: %g", sars_reactive_db()$country, sars_reactive_db()$cases, sars_reactive_db()$deaths, sars_reactive_db()$permill) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = sars_col),
textsize = "15px", direction = "auto")) %>%
addCircleMarkers(data = cv_today, lat = ~ latitude, lng = ~ longitude, weight = 1, radius = ~(cases)^(1/5.5),
fillOpacity = 0.1, color = covid_col, group = "2019-COVID",
label = sprintf("<strong>%s (cumulative)</strong><br/>Confirmed cases: %g<br/>Deaths: %d<br/>Cases per million: %g", cv_today$country, cv_today$cases, cv_today$deaths, cv_today$permill) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = covid_col),
textsize = "15px", direction = "auto")) %>%
addCircleMarkers(data = h1n1_cases, lat = ~ latitude, lng = ~ longitude, weight = 1, radius = ~(projected_deaths)^(1/4),
fillOpacity = 0.2, color = h1n1_col, group = "2009-H1N1 (swine flu)",
label = sprintf("<strong>%s</strong><br/>H1N1 deaths (confirmed): %g<br/>H1N1 deaths (estimated): %g", h1n1_cases$region, h1n1_cases$deaths, h1n1_cases$projected_deaths) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = h1n1_col),
textsize = "15px", direction = "auto")) %>%
addCircleMarkers(data = ebola_cases, lat = ~ latitude, lng = ~ longitude, weight = 1, radius = ~(cases)^(1/4),
fillOpacity = 0.2, color = ebola_col, group = "2014-Ebola",
label = sprintf("<strong>%s</strong><br/>Ebola cases: %g<br/>Deaths: %d", ebola_cases$country, ebola_cases$cases, ebola_cases$deaths) %>% lapply(htmltools::HTML),
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px", "color" = ebola_col),
textsize = "15px", direction = "auto"))
})
output$sars_cumulative_plot <- renderPlot({
sars_cumulative_plot(sars_aggregated, sars_mod_date())
})
output$sars_epi_curve <- renderPlot({
sars_new_cases_plot(sars_aggregated, sars_mod_date())
})
# comparison plot
output$comparison_plot <- renderPlotly({
comparison_plot(epi_comp, input$comparison_metric)
})
# add footnote for cases
output$epi_notes_1 <- renderText({
if(input$comparison_metric=="cases") { paste0("Note that the axis is on a log10 scale so moves in 10-fold increments.
The 60.8 million estimated cases of H1N1 dwarf all other outbreaks of plotted on a standard linear scale.") }
})
# add footnote for deaths
output$epi_notes_2 <- renderText({
if(input$comparison_metric=="deaths") {
paste0("For H1N1, the number of laboratory-confirmed deaths reported by the WHO is displayed. Subsequent modelling studies have estimated the actual number to be in the range of 123,000 to 203,000.")
}
})
# add note for cfr
output$epi_notes_3 <- renderText({
if(input$comparison_metric=="cfr") {
paste0("For COVID-19, this displays the proportion of confirmed cases who have subsequently died. When factoring in mild or asymptomatic infections that are not picked up by case surveillance efforts, current estimates place the case fatality rate in the range of 0.3-1%.")
}
})
# update region selections
observeEvent(input$level_select, {
if (input$level_select=="Global") {
updatePickerInput(session = session, inputId = "region_select",
choices = "Global", selected = "Global")
}
if (input$level_select=="Continent") {
updatePickerInput(session = session, inputId = "region_select",
choices = c("Africa", "Asia", "Europe", "North America", "South America"),
selected = c("Africa", "Asia", "Europe", "North America", "South America"))
}
if (input$level_select=="US state") {
updatePickerInput(session = session, inputId = "region_select",
choices = as.character(cv_states_today[order(-cv_states_today$cases),]$state),
selected = as.character(cv_states_today[order(-cv_states_today$cases),]$state)[1:10])
}
if (input$level_select=="Country") {
updatePickerInput(session = session, inputId = "region_select",
choices = as.character(cv_today_reduced[order(-cv_today_reduced$cases),]$country),
selected = as.character(cv_states_today[order(-cv_states_today$cases),]$state)[1:10])
}
}, ignoreInit = TRUE)
# create dataframe with selected countries
country_reactive_db = reactive({
if (input$level_select=="Global") {
db = cv_cases_global
db$region = db$global_level
}
if (input$level_select=="Continent") {
db = cv_cases_continent
db$region = db$continent
}
if (input$level_select=="Country") {
db = cv_cases
db$region = db$country
}
if (input$level_select=="US state") {
db = cv_states
db$region = db$state
}
if (input$outcome_select=="Cases (total)") {
db$outcome = db$cases
db$new_outcome = db$new_cases
}
if (input$outcome_select=="Deaths (total)") {
db$outcome = db$deaths
db$new_outcome = db$new_deaths
}
if (input$outcome_select=="Cases per million") {
db$outcome = db$permill
db$new_outcome = db$newpermill
}
if (input$outcome_select=="Deaths per million") {
db$outcome = db$deathspermill
db$new_outcome = db$newdeathspermill
}
db %>% filter(region %in% input$region_select)
})
# country-specific plots
output$country_plot <- renderPlotly({
country_cases_plot(country_reactive_db(), start_point=input$start_date, input$minimum_date)
})
# country-specific plots
output$country_plot_cumulative <- renderPlotly({
country_cases_cumulative(country_reactive_db(), start_point=input$start_date, input$minimum_date)
})
# country-specific plots
output$country_plot_cumulative_log <- renderPlotly({
country_cases_cumulative_log(country_reactive_db(), start_point=input$start_date, input$minimum_date)
})
# output to download data
output$downloadCsv <- downloadHandler(
filename = function() {
paste("COVID_data_", cv_today$date[1], ".csv", sep="")
},
content = function(file) {
write.csv(cv_cases %>% select(c(country, date, cases, new_cases, deaths, new_deaths,
permill, newpermill, deathspermill, newdeathspermill)), file)
}
)
output$rawtable <- renderPrint({
orig <- options(width = 1000)
print(tail(cv_cases %>% select(c(country, date, cases, new_cases, deaths, new_deaths,
permill, newpermill, deathspermill, newdeathspermill)), input$maxrows), row.names = FALSE)
options(orig)
})
}
#runApp(shinyApp(ui, server), launch.browser = TRUE)
shinyApp(ui, server)
library(rsconnect)
deployApp(account="vac-lshtm")