-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of dashboard version 2
- Clean slate for dashboard #41 - Update dashboard to use CovidTimelineCanada #45 - Add basic plot of case time series by province/territory (mainly as an example, plot will be removed/altered later) - Add sidebar with link to top of page (eventually, each section will be linked here)
- Loading branch information
1 parent
d6ed1f4
commit fd6d394
Showing
32 changed files
with
153 additions
and
4,532 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 |
---|---|---|
@@ -1,11 +1,10 @@ | ||
# define global | ||
source("global.R") | ||
# load pipe | ||
library(magrittr) | ||
|
||
# define UI | ||
# source components | ||
source("global.R") | ||
source("ui.R") | ||
|
||
# define server | ||
source("server.R") | ||
|
||
# run app | ||
shinyApp(ui, server) | ||
shiny::shinyApp(ui, server) |
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 |
---|---|---|
@@ -1,71 +1,39 @@ | ||
# load libraries | ||
library(dplyr) | ||
library(RJSONIO) | ||
|
||
# create data directory, if it doesn't already exist | ||
dir.create("data", showWarnings = FALSE) | ||
|
||
# download most recent data from GitHub and unzip into temporary folder | ||
temp <- tempfile() | ||
tempd <- tempdir() | ||
download.file("https://github.com/ccodwg/Covid19Canada/archive/master.zip", temp, mode = "wb") | ||
unzip(temp, exdir = tempd) | ||
# download data from GitHub | ||
|
||
# copy into local data directories | ||
# update time | ||
curl::curl_download("https://raw.githubusercontent.com/ccodwg/CovidTimelineCanada/main/update_time.txt", "data/update_time.txt") | ||
|
||
## copy data | ||
if (dir.exists(paste(tempd, "Covid19Canada-master", sep = "/"))) { | ||
for (f in list.files(paste(tempd, "Covid19Canada-master", sep = "/"), recursive = TRUE, full.names = TRUE)[basename(list.files(paste(tempd, "Covid19Canada-master", sep = "/"), recursive = TRUE)) %in% c( | ||
"update_time.txt", "data_notes.txt", | ||
"cases_timeseries_prov.csv", "mortality_timeseries_prov.csv", "recovered_timeseries_prov.csv", "testing_timeseries_prov.csv", "active_timeseries_prov.csv", | ||
"cases_timeseries_hr.csv", "mortality_timeseries_hr.csv", | ||
"cases_timeseries_canada.csv", "mortality_timeseries_canada.csv", "recovered_timeseries_canada.csv", "testing_timeseries_canada.csv", "active_timeseries_canada.csv", | ||
"vaccine_administration_timeseries_prov.csv", "vaccine_administration_timeseries_canada.csv", | ||
"vaccine_distribution_timeseries_prov.csv", "vaccine_distribution_timeseries_canada.csv", | ||
"vaccine_completion_timeseries_prov.csv", "vaccine_completion_timeseries_canada.csv", | ||
"vaccine_additionaldoses_timeseries_prov.csv", "vaccine_additionaldoses_timeseries_canada.csv", | ||
"sk_new_cases_timeseries_hr.csv","sk_new_mortality_timeseries_hr.csv" | ||
)]) { | ||
file_destination <- paste0("data/", basename(f)) | ||
message("Copying: ", file_destination) | ||
file.copy(f, file_destination, overwrite = TRUE) | ||
} | ||
} | ||
# geo data | ||
curl::curl_download("https://raw.githubusercontent.com/ccodwg/CovidTimelineCanada/main/geo/pt.csv", "data/pt.csv") | ||
curl::curl_download("https://raw.githubusercontent.com/ccodwg/CovidTimelineCanada/main/geo/pt.geojson", "data/pt.geojson") | ||
curl::curl_download("https://raw.githubusercontent.com/ccodwg/CovidTimelineCanada/main/geo/health_regions.csv", "data/health_regions.csv") | ||
curl::curl_download("https://raw.githubusercontent.com/ccodwg/CovidTimelineCanada/main/geo/health_regions.geojson", "data/health_regions.geojson") | ||
|
||
## copy other files | ||
if (dir.exists(paste(tempd, "Covid19Canada-master", sep = "/"))) { | ||
for (f in list.files(paste(tempd, "Covid19Canada-master", sep = "/"), recursive = TRUE, full.names = TRUE)[basename(list.files(paste(tempd, "Covid19Canada-master", sep = "/"), recursive = TRUE)) %in% c( | ||
"prov_map.csv", "hr_map.csv","hr_map_sk_new.csv" | ||
)]) { | ||
file_destination <- paste0("data/", basename(f)) | ||
message("Copying: ", file_destination) | ||
file.copy(f, file_destination, overwrite = TRUE) | ||
} | ||
# health region data | ||
for (d in c( | ||
"cases", | ||
"deaths" | ||
)) { | ||
curl::curl_download(paste0("https://github.com/ccodwg/CovidTimelineCanada/raw/main/data/hr/", d, "_hr.csv"), paste0("data/", d, "_hr.csv")) | ||
} | ||
|
||
# download hospitalization data | ||
hosp <- fromJSON("https://api.covid19tracker.ca/summary/split")$data %>% | ||
lapply(function(x) { | ||
x[sapply(x, is.null)] <- NA | ||
unlist(x) | ||
}) %>% | ||
{as.data.frame(t(do.call("cbind", .)), stringsAsFactors = FALSE)} %>% | ||
rename( | ||
prov_short = province, | ||
hosp_cases = total_hospitalizations, | ||
hosp_cases_change = change_hospitalizations) %>% | ||
inner_join( | ||
data.frame("prov_short" = c("NL", "PE", "NS", "NB", "QC", "ON", "MB", "SK", "AB", "BC", "YT", "NT", "NU"), | ||
"province" = c("NL", "PEI", "Nova Scotia", "New Brunswick", "Quebec", "Ontario", "Manitoba", | ||
"Saskatchewan", "Alberta", "BC", "Yukon", "NWT", "Nunavut"), | ||
stringsAsFactors = FALSE), | ||
by = "prov_short" | ||
) %>% | ||
select(province, hosp_cases, hosp_cases_change) | ||
|
||
# write hospitalization data | ||
write.csv(hosp, "data/hosp.csv", row.names = FALSE) | ||
# province/territory data | ||
for (d in c( | ||
"cases", | ||
"deaths", | ||
"tests_completed", | ||
"vaccine_coverage_dose_1", | ||
"vaccine_coverage_dose_2", | ||
"vaccine_coverage_dose_3", | ||
"vaccine_coverage_dose_4" | ||
)) { | ||
curl::curl_download(paste0("https://github.com/ccodwg/CovidTimelineCanada/raw/main/data/pt/", d, "_pt.csv"), paste0("data/", d, "_pt.csv")) | ||
} | ||
|
||
# delete temporary files | ||
unlink(temp) # delete GitHub download | ||
unlink(paste(tempd, "Covid19Canada-master", sep = "/"), recursive = TRUE) # delete unzipped files | ||
# metadata | ||
for (d in c("cases", "deaths")) { | ||
curl::curl_download(paste0("https://github.com/ccodwg/CovidTimelineCanada/raw/main/data/can/", d, "_can_completeness.json"), paste0("data/", d, "_can_completeness.json")) | ||
} |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.