Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An example of how we update a Datawrapper chart with R
# Update our worldwide cases chart
# We would replace `chartid` below with the chart’s Datawrapper id
# https://app.datawrapper.de/chart/chartid/publish
# Clean our data and get it ready for the chart
chartid <- data %>%
group_by(date) %>%
# reshape so "cases" is one column and "deaths" is another
dcast(date ~ variable, value.var = "value", fun.aggregate = sum) %>%
select(date, `Confirmed cases`, Deaths = deaths)
# Sent data to chart and republish
httr::handle_reset(paste("https://api.datawrapper.de/v3/charts/", "chartid"))
# Add a timestamp
dw_edit_chart(chart_id = "chartid", annotate = paste("Data correct as of", format(Sys.time(), "%l:00%p %b %d"), sep=""))
dw_data_to_chart(`chartid`, chart_id = "chartid")
dw_publish_chart(chart_id = "chartid")
# Update our GIF
# With a couple lines of code we send a (gif_data) in R to an S3 bucket as a .json file
exportJSON <- toJSON(gif_data)
write(exportJSON, "export/data.json")
put_object(file="export/data.json", object="data.json", bucket="bucket-name")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment