I was wondering whether someone could help me with the following (I posted the same question on SO but haven't received any answer so far; will cross-post if so):
Here’s a (openstreet) map which contains covid vaccination rates for the municipal level. I am able to extract (parts of) this data by using the relevant json file from the Network/XHR panel in my browser (Chrome).
I simply read the identified file with jsonlite::fromJSON(my_json_link)
. So far so good.
Here’s the problem: The data displayed on the map is not contained in one single json file but dispersed over multiple files and collecting them individually is cumbersome. How can I extract the links to all json-files automatically (and not manually)?
The problem seems to be aggravated by the fact that the relevant json files appear in the Network/XHR panel only once e.g. a specific municipality had been zoomed-in or clicked on. Before, the pertaining json file simply does not show up. It seems to me I have to ‘trigger’ all municipalities first, and then extract the files.
Below the code I have been using so far (the list of links is not exhaustive).
I also saw this post but failed to adapt it to my purpose.
Many thanks for any hint.
library(jsonlite)
library(tidyverse)
vec_json_links <-c(
"https://pipe.orf.at/globus-2020/maps/153/269/9/277/176.json",
"https://pipe.orf.at/globus-2020/maps/153/269/9/278/176.json",
"https://pipe.orf.at/globus-2020/maps/153/269/9/279/176.json",
"https://pipe.orf.at/globus-2020/maps/153/269/7/69/44.json",
"https://pipe.orf.at/globus-2020/maps/153/269/7/69/45.json",
"https://pipe.orf.at/globus-2020/maps/153/269/7/70/44.json",
"https://pipe.orf.at/globus-2020/maps/153/269/8/135/89.json",
"https://pipe.orf.at/globus-2020/maps/153/269/8/136/89.json",
"https://pipe.orf.at/globus-2020/maps/153/269/8/137/89.json",
"https://pipe.orf.at/globus-2020/maps/153/269/8/138/89.json",
"https://pipe.orf.at/globus-2020/maps/153/269/8/138/90.json",
"https://pipe.orf.at/globus-2020/maps/153/269/8/139/89.json",
"https://pipe.orf.at/globus-2020/maps/153/269/8/140/89.json",
"https://pipe.orf.at/globus-2020/maps/153/269/10/559/356.json",
"https://pipe.orf.at/globus-2020/maps/153/269/10/555/356.json",
"https://pipe.orf.at/globus-2020/maps/153/269/10/559/354.json",
"https://pipe.orf.at/globus-2020/maps/153/269/10/555/354.json",
"https://pipe.orf.at/globus-2020/maps/153/269/10/559/355.json",
"https://pipe.orf.at/globus-2020/maps/153/269/10/555/355.json",
"https://pipe.orf.at/globus-2020/maps/153/269/10/558/356.json")
fn_get_data <- function(json_link) {
json_data<-jsonlite::fromJSON(json_link)
unlist(json_data$data) %>%
enframe() %>%
mutate(municip_id=str_extract(name, regex("\\d+"))) %>%
mutate(municip_name=str_extract(value, regex("(?<=\\>).*(?=\\<)"))) %>%
mutate(vacc_full=str_extract(value, regex("(?<=Vollimmunisiert\\:).*?(?=\\%)")) %>%
str_trim(.) %>% as.numeric) %>%
mutate(vacc_part=str_extract(value, regex("(?<=Teilimmunisiert\\:).*?(?=\\%)")) %>%
str_trim(.) %>% as.numeric)
}
df_vaccination <- vec_json_links %>%
purrr::set_names() %>%
map_dfr(., fn_get_data, .id="link")