Coding club is meant to build coding skills in R, HTML, CSS, and JavaScript. You don’t need to have any experience apart from basic R.

Autumn 2022: Creating an R Package

Wednesdays from 16:05 to 17:00 UK time from October 5 to December 7.

Our next set of sessions will be making your own R package. Making an R package develops generic coding skills and gives you valuable insight to how R works. We’ll cover setting up a package project, creating functions, documenting them with roxygen, creating vignettes, unit testing, package testing, version control with git, and distribution with github.

Register on Eventbrite for free (this just helps us track interest).

Book/Code – this will update regularly before sessions to show what we intend to cover, and after sessions to document what we did actually cover.

You will need only very basic R skills and a willingness to learn. The only people this would not be suitable for are those with zero previous experience in R (unless you know you pick up coding languages quickly). If you can install packages and understand the following code, you should be fine:


df <- data.frame(
  id = 1:10,
  name = LETTERS[1:10],
  score = rnorm(10, mean = 100, sd = 10)

ggplot(df, aes(x = name, y = score)) +
  geom_point() +


The schedule below is only indicative. Coding club is much less formal than a class, so the tasks might move around depending on the skill and interests of the attendees.

1. Setting up


Create a package project and edit the default files. We’ll start using the most helpful package, usethis.

2. Adding Data


Add datasets to your package and document them with a codebook. You can use our demo data or your own.

3. Custom Functions


Learn to write custom functions and include them in your package.

4. Documentation


Write function documentation using the roxygen format. This is what creates the help documentation for functions.

5. Analysis Vignette


Include your study analysis code as a package vignette.

6. Pkgdown Websites


Create a package website using pkgdown.

7. Unit Tests


Write unit tests for your custom functions using testthat.

8. Package Maintenance


How to run CMD-check to make sure everything is put together right, and how to troubleshoot the inevitable problems.

9. Sharing your package


Set up a github account and make a package repository to share your package and pkgdown website.

10. Next steps


Whatever we didn’t get to. We’ll also discuss how to continue your learning.

Autumn 2021: Database App

In autumn 2021, we’ll be making a custom web app for searching, visualising and updating a list of anything you’re interested in. The focus will be learning by doing, but the sessions will be supported by material from Building Web Apps with R Shiny.

1. Setting Up the Framework

2021-10-06 14:00 (Europe/London)

Before the session:

  1. Check out the demo app
  2. Bookmark the book
  3. Install the {shinyintro} package
# you may have to install devtools first with 
# install.packages("devtools")


In this first session, we:

  • created a project with the demo shiny app
  • discussed the structure of a shiny app
  • added a new sliderInput widget for binwidth and changed the plot to a ggplot


2. Reading Data from a GoogleSheet

2021-10-20 14:00 (Europe/London)

Before the session:

  • make sure you have the R packages shiny, shinydashboard, and tidyverse (these will already be installed if you installed the shinyintro package as mentioned in week 1)

In this second session, we:

  • made a Google form to collect data about book recommendations and save it into a public Google Sheet
  • set up the UI (user interface) for our app


3. Filtering Data

2021-11-03 14:00 (Europe/London)

In this third session, we:

  • selected columns to display
  • filtered the book table by genre

You can work on your own to add filtering for language and/or page length. Remember that all the columns are character columns and you need to deal with the page number entry that contains non-numeric characters.


4. Filtering Data 2

2021-11-10 14:00 (Europe/London)

In this fourth session, we:

  • updated the table to DT for text search
  • added select/unselect all buttons for the genre filter
  • added a page length selector


5. Input Interface

2021-11-24 14:00 (Europe/London)

In this fifth session, we will:

  • create an input tab so people can add their ratings of the books
  • write the rating data to another google sheet
  • read in the saved rating data and join it to the book table
  • add filters by average rating


6. Make it Functional

2021-12-08 14:00 (Europe/London)

In this seventh session, we will:

  • make sure the user interface has a clear design
  • add help messages
  • clean user inputs

7. Make it Pretty

2021-12-15 14:00 (Europe/London)

In this last session, we will:

  • use CSS to change the style of the app

Summer 2021: Distribution Simulation App

1. Setting Up the Framework

2021-05-12 14:00 (Europe/London)

  1. Check out the demo app
  2. Download the template
  3. You can access the code for the final app at

In this first session, we:

  • discussed the structure of a shiny app
  • created inputs for a random uniform distribution (runif())
  • generated random data with the input parameters and created a plot
  • output the plot

To prep for the next meeting, I’d like you to:

  • create another tab with inputs and a plot for the normal distribution
  • make your ggplot prettier (e.g., set colour and fill for the histogram)


2. Input checking

2021-05-26 14:00 (Europe/London)

In this second session, we added the normal distribution tab, used a fluidRow to put the plot next to the input, and learned how to check the user input for errors, such as impossible values, and handle these without crashing.

To prep for the next meeting, I’d like you to:

  • add error checking for the normal distribution tab
  • create another tab with inputs and a plot for the binomial distribution


3. Distribution comparisons

2021-06-09 14:00 (Europe/London) Zoom link

In this third session, we restructured the simulation functions to keep a record of previously simulated data to make faceted plots for comparison. We learned a lot about debugging.

The video ends with an unresolved bug. The resolution is to make sure that input$unif_submit is definitely an integer when you add it to the data table. I really don’t know why this fixes it. So the relevant code in the observeEvent() function for unif_submit should be:

data <- data.frame(
    x = x,
    sample = as.integer(input$unif_submit),
    n = input$unif_n,
    min = input$unif_min,
    max = input$unif_max

To do:

  • Update the norm and binomial functions to display multiple plots
  • Make your ggplots prettier
  • Make it handle plots with different parameters well. You can either give all facets the same values, or set the axes to vary by facet (or you can give users the option to choose which)
  • Think about how you’d want to visualise these distributions and create your own interface options


Spring 2021: Buzzfeed-style App

1. Setting Up the Framework

2021-03-17 14:00 (Europe/London)

  1. Check out the demo app
  2. Download the template
  3. You can access the code for the final app at

In this first session, we:

  • discussed the structure of a shiny app
  • edited the main tab to have a collapsible box for each question
  • added six custom image buttons for the first question
  • wrote a function to more easily set up a custom image button
  • edited the www/custom.css file to remove the background and padding from the custom image buttons

To prep for the next meeting, I’d like you to:

  • decide what your quiz theme and questions will be
  • find images for each question (Pixabay is a good site for open-access images)
  • set up a few questions with image buttons
  • Edit the info tab to include image citation information

The password for the session recording is on the coding club channel of the Methods and MetaScience Team. Contact Lisa to be added if you’re at Glasgow, or to ask for the password if you’re not.

You can download a zip file with the code for our current progress.

2. Button Actions

2021-03-31 14:00 (Europe/London)

In this second session, we:

  • used CSS to set the style of selected and unselected buttons
  • used observeEvent() to change the style of buttons when clicking on them
  • wrote a custom function to do this for all image buttons, using their question number and colour name

To prep for the next meeting, I’d just like you to:


3. Outputs

2021-04-14 14:00 (Europe/London)

In this third session, we:

  • updated the custom function Q() to close the current question box and open the next one
  • created a new feedback tab and added it to the UI
  • used observeEvent() to respond to clicking the submit button
  • used reactiveValues() to create values for saving the image button answers and plot
  • made a feedback plot with outputPlot() and renderPlot() that creates a plot from the quiz answers

To prep for the next meeting, I’d like you to:

  • make your feedback plot nicer, especially thinking about font sizes
  • if you want further challenge, add feedback text in addition to the plot using textOutput() and renderText()


4. Saving Data

2021-04-28 14:00 (Europe/London)

In this fourth session, we:

  • Added a button to allow participants to save their data
  • added conditional properties so the button could only be used once, after the quiz was completed
  • Learned to save data in a CSV file
  • Read the full data from the saved file and created a feedback visualisation
  • Discussed pros and cons of local storage of saved data