• Skip to primary navigation
  • Skip to main content
The Data Lab

The Data Lab

Pruple button with the word menu
  • About Us
        • About Us

           
          Visit our About Us page

        • Careers
        • Our Team
        • Impact
        • The Scottish AI Alliance
        • Contact us
  • Business
        • For Business

           

          Visit our Business Support page

        • Access Talent
        • Funding and Business Support
        • Partnerships
  • Professionals
        • For Professionals

           

          Visit our Professional Development page

        • Online Courses
        • Data Skills for Work
  • Students
        • For Students

           

          Visit our Students page

        • The Data Lab Academy
        • Student Placements
        • Scholarships
  • Universities and Colleges
        • For Universities and Colleges

           

          Visit our Universities and Colleges page

        • Funding and Support
        • Collaborate and Innovate
        • Academic Projects
  • Community
        • Community

           

          Visit our Community page

        • Online Community
        • News
        • Case Studies
        • DataFest

Exploring transport routes, journey characteristics and postcode networks using R Shiny

Technical Skills 19/06/2018

Hi all,

Recently I’ve finished work on a project intended to visualise the traffic flow within a subsidised transport service, operated by a Scottish council. This visualisation needed to display variations in traffic flow conditional on factors such as the time of day, day of the week, journey purpose, as well as other criteria. The overall aim here was to explore and identify areas of particular activity, as well as provide some insight into how this transport service might be improved.

Given the richness of the data and the multitude of (potential) influences on traffic volume, I set out to create an interactive R Shiny app. I then demoed the app at an EdinbR meeting. There it sparked a lot of interest and questions, so in the end we decided to make the underlying R code widely available (however without the associated data – which we do not own).

Prior to visualising the data within the Shiny app, it underwent some cleaning and transformations. Afterwards, I used the stplanr package (as well as the GraphHopper routing engine) to create the spatial lines connecting the origins and destinations for each unique journey. After these preliminary steps (which are not part of the code linked below), I was able to move on to creating the Shiny app itself.

Please note that, in the absence of the original data, and having removed/modified certain lines of code, the script will not run as is. Rather, it is intended to help you see the structure of a Shiny app, which you can adapt for your own purposes if you please cite this work as:

Constantinescu, A.C. (2018, June). Exploring transport routes, journey characteristics and postcode networks using R Shiny [R script as GitHub Gist]. Edinburgh, Scotland: The Data Lab Innovation Centre. Retrieved [Month] [Day], [Year], from https ://gist.github.com/CaterinaC/4fdfe9bfd753dd47bdec16ca342c401b

The app would look roughly like this (by the way, I’ve either blurred or deleted information that doesn’t belong to me):

 

Hope this is of use! Remember you can always get in touch below if you have questions or suggestions.

Tags: App, R

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *

Innovate • Support • Grow • Respect

Get in touch

t: +44 (0) 131 651 4905

info@thedatalab.com

Follow us on social

  • Twitter
  • YouTube
  • Instagram
  • LinkedIn
  • TikTok

The Data Lab is part of the University of Edinburgh, a charitable body registered in Scotland with registration number SC005336.

  • Contact us
  • Partnerships
  • Website Accessibility
  • Privacy Policy
  • Terms & Conditions

© 2025 The Data Lab