forked from AndreasFischer1985/dashboard-deutschland-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
api_example.R
24 lines (20 loc) · 1.01 KB
/
api_example.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
# Get all indicator-ids
#----------------------
url0="https://www.dashboard-deutschland.de/api/dashboard/get"
dat0=httr::content(httr::GET(url0))
clusterIDs=sapply(dat0,function(x)x$id)
indicatorIDs=sapply(dat0,function(x)sapply(x$layoutTiles,function(y)y$indicatorid))
names(indicatorIDs)=clusterIDs
# Get all data on all indicator-ids
#----------------------------------
url1=paste0("www.dashboard-deutschland.de/api/tile/indicators?ids=",paste(unlist(indicatorIDs),collapse=";"))
dat1=httr::content(httr::GET(url1))
length(dat1)==length(unique(unlist(indicatorIDs)))
json=sapply(dat1,function(x)rjson::fromJSON(x$json))
# Output Markdown-table
#----------------------
tab=paste(c("|Indikator|ids-value|Beispiel-URL|","|---|---|---|",
sapply(dat1,function(x)paste0("|",x$title,"|",x$id,"|www.dashboard-deutschland.de/api/tile/indicators?ids=",x$id,"|"))),
collapse="\n")
writeLines(tab,"table.txt")
writeLines(paste(sapply(dat1,function(x)paste0("- ",x$id," (",x$title,")")),collapse="\n"),"list.txt")