Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
library(DatawRappr)
# First create a single chart in Datawrapper, style it and download the metadata:
metadata_chart <- dw_retrieve_chart_metadata(chart_id, api_key)
# drag out the visualize-part and save it to disk:
visualize <- metadata_chart[["content"]][["metadata"]][["visualize"]]
saveRDS(visualize, "visualize.RData")
# create a list that stores each created chart id:
result_list <- list()
# start a for loop (in this example we're using countries out of a vector of countries):
for (country in country_vector) {
raw_data_frame %>%
filter(countries == country) %>%
pull(country_name) -> country_name
current_chart <- dw_create_chart(title = paste0("Chart für ", country_name),type = "d3-lines")
dw_edit_chart(chart_id = current_chart, visualize = visualize)
published_chart <- dw_publish_chart(current_chart)
result_list[[i]] <- data.frame(country = country_name, url = published_chart$publicUrl, iframe = published_chart$iframeCode, chart_id = published_chart[["content"]][["data"]][[1]][["id"]])
}
# save list to disk for updating the charts:
result_df <- dplyr::bind_rows(result_list)
saveRDS(result_df, "chart_ids.RData")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.