Lab 1 - Intro to Shiny

General Lab Instructions. (15)


  • Ensure your lab meets these basic lab requirements:
  • Ensure that the low-level flow of your writing is appropriate, with full sentences and using proper English, spelling, and grammar.
  • Ensure that the high-level structure of your solution is clear and thorough for each answer, with a well-thought-out organization of concepts that avoids repetition.
  • This assignment is to be completed as a shiny app. However, your answers should be submitted as both a .Rmd markdown file you create in RStudio (you can add your answers directly to this one) along with a rendered .md AND .pdf file.
  • Ensure your submission is formatted clearly as to distinguish between questions and answers. For an example, check the formatting_template directory of the course repository.
  • Ensure that your markdown submission as a whole is easy to read: use appropriate formatting that clearly distinguishes between our questions and your answer, between different sub-parts of your answer, and with visible differences between code and English.
  • Deploy your Shiny app to and upload your source code to your assignment repository. Sometimes deployment will introduce bugs, so make sure to save some time for debugging! The console logs are very helpful here.

Exercise 1 - Interactive plots with Shiny and the US violent crimes 1975-2015 dataset

Create an interactive visualization using Shiny and the Marshall dataset of violent crimes in 68 US cities from 1975-2015.

Q1a: Choose and justify visual encoding and interaction idioms. (9)

  • Consider what questions might be answerable with this dataset, and consider what visual encodings would be appropriate that take into account these inferred tasks and the characteristics of the dataset.
  • Also consider how to add interactivity that would further support these tasks through dynamic changes, either of aspects of the visual encoding or by providing alternate visual encodings.
  • Explain and justify your choice of visual encodings with respect to the dataset characteristics and the tasks that you inferred, including an analysis of marks and channels.
  • For each visual channel used, state "Channel X encodes attribute Y of type Z".
  • For each mark used, state "Mark of type X encodes item Y".


Q1b: Create a base visualization within the Shiny framework by visually encoding the dataset, according to your choices above. (12)


Q1c: Make the visualization interactive. (64)


You should implement at least five input methods. You may tie these to any of the attributes in the dataset or to any aspects of the visual encoding. Here are some ideas:

  • date range - filter by dates
  • select input - pick which attribute to encode, or pick which encoding to use
  • numeric input - change geom alpha/transparency value, or change attribute thresholds
  • radio buttons - change geom type, or change between showing raw and normalized data
  • slider input - change geom size, or change attribute thresholds
  • checkbox input - pick a region, or pick a crime type
  • text input - change graph title/legend, or add annotation
  • color input - change geom color
    + library(colourpicker) # library(devtools); devtools::install_github("daattali/colourpicker")

Deploy your app to and include the source code in your homework repository.

Briefly explain the functionality of your interactive Shiny app in your writeup.

Q2 (optional) Add more interactive functionality (6)


Dig further into the docs to go above and beyond the suggestions listed above and implement some novel functionality.