Jean-Paul R. Soucy
Let's scrape the 14-day school-associated case counts from the Manitoba Schools Dashboard.
We begin by loading the package we need to grab the JSON data.
# load packages
# install.packages(jsonlite) # install if necessary
library(jsonlite)
Next, we load the JSON file and grab the data of interest.
# load data
schools <- fromJSON("https://services.arcgis.com/mMUesHYPkXjaFGfS/arcgis/rest/services/mb_covid_education_2week_map/FeatureServer/0/query?f=json&where=1%3D1&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*")$features$attributes
Let's take a glance at the data.
# preview data
head(schools)
## school_name cases_last_two_weeks cases_since_1_sept school_nbr
## 1 ANDREW MYNARSKI V.C. SCHOOL 1 NA 1061
## 2 ARTHUR E. WRIGHT COMMUNITY SCHOOL 1 NA 1088
## 3 BALMORAL HALL SCHOOL 1 NA 1536
## 4 BOISSEVAIN SCHOOL 1 NA 1521
## 5 CALVIN CHRISTIAN SCHOOL 1 NA 1077
## 6 CECIL RHODES SCHOOL 2 NA 1113
## school_postal_code Latitude Longitude student_count div_nbr div_name school_tcount
## 1 R2X1H6 49.93530 -97.16436 382 151 WINNIPEG 1
## 2 R2P1K1 49.95878 -97.17555 539 118 SEVEN OAKS 0
## 3 R3C3S1 49.88167 -97.15640 437 107 INDEPENDENT SCHOOLS 0
## 4 R0K0E0 49.23636 -100.06036 380 141 TURTLE MOUNTAIN 0
## 5 R2G0T1 49.94365 -97.08422 474 107 INDEPENDENT SCHOOLS 0
## 6 R3E1C2 49.91680 -97.19155 615 151 WINNIPEG 2
## division_enrolment_2019 ObjectId
## 1 32743 1
## 2 11800 2
## 3 0 3
## 4 1043 4
## 5 0 5
## 6 32743 6
Note that school_tcount
refers to the number of VOC cases in the school.
Finally, we export the data as a CSV.
# save data
write.csv(schools, "mb_schools.csv")
Here's the full script:
# load packages
# install.packages(jsonlite) # install if necessary
library(jsonlite)
# load data
schools <- fromJSON("https://services.arcgis.com/mMUesHYPkXjaFGfS/arcgis/rest/services/mb_covid_education_2week_map/FeatureServer/0/query?f=json&where=1%3D1&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*")$features$attributes
# preview data
head(schools)
# save data
write.csv(schools, "mb_schools.csv")