2 min read

Deer-vehicle collisions: a Shiny app

Matt Dray (@mattdray)

Open data

Deer roam Scotland. So do humans. It’s a problem when they meet at high speed.

The National Deer-Vehicle Collisions Project, administered by The Deer Initiative, has been monitoring data on deer-vehicle collisions in the UK.

The data are open. I found the dataset when skimming through data.gov.uk (a classic weekend activity for all the family). It links to the SNH Natural Spaces site where you can download the data as shapefile, GML or KML under the Open Government Licence.

I couldn’t find an interactive visualisation of these data and I don’t spend much time working with R Shiny,1 so why not.

A simple Shiny app

I recommend you check out the full-screen app live at mattdray.shinyapps.io/scot-deer-collisions/.

I’ve embedded a compact version of it below (it’ll take a moment to load). Click the for the options menu to start filtering the data.

The code for the app is available on GitHub. You can also download the cleaned data in CSV or RDS format.

It was built in R with:

In case you still aren’t sure, here’s a gif of the full app in action.

Engifified look at the fullscreen app

Engifified look at the fullscreen app


I may update the app in future or take it down entirely. It’s hosted for free at shinyapps.io, which means that it can only receive a fixed number of visits each month before it becomes unavailable. The code will continue to exist on GitHub where you can leave an issue or fork it to make it better.

I limited the filters to year, month and local authority. I could have included deer species and road, but the data are sparse and the formatting wasn’t great. I cleaned these variables up a bit and they’re available as filterable columns in the interactive table.

There’s a large number of points and it doesn’t make sense to show them all at once because it slows the app down. There are methods for improving this, but I assume most people will be looking at specific local authorities or roads rather than the country as a whole.

  1. But see this post about a Shiny app I made that that one colleague described as ‘very depressing’.