Adding informative alternative text (alt text) to images is a fundamental principle of web accessibility. Currently Shiny does not have an option to add alt text to a dynamic plot created with the renderPlot() function. This article demonstrates a method of achieving this.

Histogram plot showing HTML with accessibility features and attributes overlayed in the columns.
Histogram plot showing HTML with accessibility features and attributes overlayed in the columns.

A Common Problem

Having discovered that there was no equivalent of the renderImage() alt parameter for renderPlot() I started searching for solutions and found a thread on this subject in the RStudio Shiny repo on GitHub. Within this thread a solution is referred to by leonawicz using observers to add alt text to dynamic plots using their id, in the…

This tutorial shows you how to use the rtweet R package to retrieve tweets from Twitter’s REST API and explore the results using functions from the tidyverse and tidytext packages. We’ll look at tweets with the hashtag #ClimateEmergency over the New Year period and identify the most common emoji, hashtags, username mentions and words.

Install and load rtweet

You can install the rtweet package from CRAN by executing install.packages(“rtweet”). We then need to load the package along with the tidyverse suite of R packages to manipulate the data and tidytext to tokenise the tweet text into words.

library(rtweet) ; library(tidyverse) ; library(tidytext)

Getting Twitter API access

Before you…

[M]ankind is challenged, as it has never been challenged before, to prove its maturity and its mastery — not of nature, but of itself.

Rachel Carson

By the middle of 2019 more than half of the UK’s local councils had declared a ‘climate emergency’. Many of these also announced carbon reduction targets. For example, London and Greater Manchester have committed to net zero emissions targets by 2038.

To help councils prepare their climate change plans we’ve curated a list of open datasets. We sourced and cleaned local authority level datasets on a range of climate change indicators including carbon emissions…

The UK Office for National Statistics' Open Geography Portal provides a range of geospatial datasets under the Open Government Licence 3.0. Digital vector boundaries for different administrative and statistical geographies, postcode centroids and lookups are all available to freely download. This post will show you how to download digital vector boundaries for custom administrative geographies using the Open Geography Portal API.

What’s available?

Digital vector boundaries on the Open Geography Portal come as ESRI shapefiles, KML or GeoJSON files in full resolution or in one of three generalised formats:

  • Generalised (20m)
  • Super generalised (200m)
  • Ultra generalised (500m)

It is recommended that high…

This is a short introduction to creating choropleth maps in Vega-Lite. We’ll show you how to load geospatial data, customise maps and join attributes.

What is Vega-Lite?

Vega-Lite is an open source tool that allows you to turn raw data into a range of interactive visualisations. You read, transform and encode your data to visual properties in a single JSON file that can be embedded in a web page.


The easiest way to start creating maps in Vega-Lite is to use their online editor. …

Most local government employees reach for spreadsheets when they need to create a chart. However, spreadsheet programs can reinforce bad visualisation practices by not making the process required to build a graphic explicit. Chart templates provide quick and easy ways to create a graphic but they teach little about how visualisations are constructed or how they encode data.

In this article, we recommend Vega-Lite because it allows users to quickly build visually appealing static and interactive data visualisations in their web browser. …

Opening up government data enables third parties to develop innovative new tools that can help public services and the citizens that they serve. Our Crime Scanner application uses reported crimes published by the Home Office on and digital vector boundaries available on the Office for National Statistics' Open Geography Portal under the Open Government Licence v3.0 to visualise crimes and incidents of anti-social behaviour (ASB) at Local Authority, Electoral Ward and Lower-layer Super Output Area Level.

Using the app

The Crime Scanner application is divided into four panes: summary, bar chart, time series, and map.

The four panes of Crime Scanner
  • The summary pane provides an overview of…

The Trafford Data Lab is involved in one of the six EU-funded OpenGovIntelligence (OGI) pilot projects which aim to make better use of linked open statistical data to help improve the design and delivery of public services. Each pilot involves a technical partner responsible for creating tools that help standardise the publication of multidimensional data and a public sector agency tasked with exploiting them for the benefit of public services.

The aim of the Trafford Worklessness Pilot is to help support Jobcentre Plus teams in Greater Manchester that deliver services that help people into work by co-creating web applications that…

The Trafford Data Lab have just released their Reachability plugin for LeafletJS, an open-source JavaScript library for interactive maps, which uses the openrouteservice API to create network distance buffers and travel time isochrones. A working version of the plugin is available on our Explore mapping application.

The Reachability plugin enables users to draw areas of equal distance or travel time from a given location. This can be useful for:

- determining how many pharmacies are within a 10 minute walk of a GP
- comparing public transport accessibility with employment opportunities
- drawing school catchment areas

Knowledge of the distance…

Governments and other organisations often make open data available through Web service Application Programming Interfaces or APIs. The World Bank, UK Police, and Transport for London are just a few well-known examples. This article details the steps required to request data from these different Web service APIs using R.

Several R packages¹ have been developed as clients for Web service APIs. These don’t assume any knowledge of API endpoints, HTTP requests, or data formats like XML and JSON. These are really convenient but sometimes you want to break into the ‘black box’ of APIs …

A quick introduction to APIs

APIs or Application Programming Interfaces…

Trafford Data Lab

Supporting decision-making in Trafford by revealing patterns in data through visualisation.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store