This server is my R playground–everything here is made with R. This site is made with RMarkdown, while other projects here are Shiny apps, or make use of rApache. I’ve been using R increasingly since 2017 and it’s been great fun finding out what this language can do.

Apps using Shiny

My first experience with R was using Shiny. In the summer of my first year as an biology undergrad (2017) I was drafted to help my degree programme coordinator create a range of Shiny apps for one of his 3rd and 4th year modules–Population and Community Ecology.

The aim was to hide all the R code, which previously made this module particularly difficult, and turn each lesson into an interactive learning experience. The scripts were already coded, so my job was to turn everything into nice clean functions and wrap it all in Shiny …once I’d figured out what Shiny was.

These apps are still in use today and there’s been lots of positive feedback from other students (they seem very glad they no longer have to code to take this module!).

Have a nosey at the apps


Dr Tim Paine ran this project, provided all the original R code, and had final control over input and output formatting. These apps have since been taken over by Dr Bruce McAdam.

Modelling with rApache

As a web developer (that’s my past life) I found Shiny quite constraining. It is absolutely great for creating quick interactive sites and documents, especially via RMarkdown, but I didn’t really want to use R to code all my HTML all of the time; it was an abstraction and I wanted finer control. On my hunt for other things to try I came across rApache. I already had Apache running so it wasn’t too hard to add this module and get R code working right inside my HTML files. This was pretty exciting! (yeah I know, but it was). Not too long after, in the summer of my second year as an undergrad (2018), I got an opportunity to put this to some use.

I had volunteered to help with an interesting biocontrol experiment that aimed not to fight evolution, but to use it as a weapon instead. We were working with crop pest, Helicoverpa armigera, a polyphagous moth that is high up on agriculture’s most wanted list. The basic concept of the project was that increasing complexity of the environment would retain genetic variation in our pest and put a halt to selective sweeps of pesticide resistance. The mechanics to demonstrate this were modelled in R by Dr Brad Duthie and I was asked, amongst the gardening and feeding duties, to help make the model output easy to understand. So, I designed and built an interface using HTML, CSS and JS. Brad and I worked together (collaborating via GitHub) to get the model to output JSON arrays that I could use to manipulate the page. I was able to run the model’s R functions directly because the server uses rApache. The output could then be passed right to JS which controls markup changes on the page, styled with CSS.

The result

A completely custom model interface, which we have very fine control over.

Play with the model

What the model shows

There aren’t many details on the interface itself, about what the model shows; it’s designed to use as part of an oral presentation where the speaker describes what is happening. The landscape–four patches of crops–can be manipulated via two slider controls. The number of crops and pathogens are then rotated across patches over a number of generations. The final generation of H. armigera (either those before an extinction, or those that survive to 19 generations) are returned.

  • Faces
    Each face represents a proportion of surviving H. armigera.
  • Colour
    Represents genetic diversity within the population. The more colours and shades of colours you see, the more genetic diversity there is.
  • Size/Emotion
    Indicates feeding prowess and pathogen resistance.
    • Large and smiling faces
      Represent individuals which can eat the crop and resist the pathogen.
    • Medium and indifferent faces
      Represent individuals which can either eat the crop or resist the pathogen, but can’t do both.
    • Small and sad faces
      Represent individuals which can’t eat the crop or resist the pathogen. These genotypes will be the cause of future extinctions.

Plans for the future

At the moment this is a toy model to convey the idea of the project. There are lots of plans for improvements when the real data are available. We’re all looking forward to seeing how it pans out!


Dr Luc Bussière, Dr Matthew Tinsley and Dr Rosie Mangan ran this project and Dr Brad Duthie was responsible for all the model’s heavy lifting.

Statistics in R

In my third year, I’ve finally got down to the nitty gritty of R and I’ve begun to learn statistics. I’ll be adding the things I learn here as a handy reference for myself.

See my stats notes