ERP visualization: Basic Shiny Demo

Shiny app

In an unusual fit of enthusiasm, I decided to have to go at writing a little app in Shiny, a simple programming framework to make web-based apps using R. So, as usual, all programmed using RStudio, the devs who also make Shiny and various fantastic R packages such as dplyr and ggplot2.

It turned out to be pretty simple. I’m planning to add various additional functions as I get time to work on my blog posts, like allowing people to use their own data, for example. I’ve uploaded the current app to, so you can have a play with it by clicking here.

All the code is available over on my Github page, as is the R Markdown code for the whole blog. If you want to try using the app with your own data, you should be able to do it by downloading the code yourself and running it in R. You’d need to modify the early lines where it loads the data -

levCatGA <- read_csv("data/levCatObjNon.csv",
                     col_names = c("Object", "Non-Object", "Time", "Subject")) %>%
  mutate(Difference = Object - `Non-Object`) %>%
  gather(condition, amplitude,-Time,-Subject) %>%
  mutate(effectType = factor(if_else(condition == "Difference", "Difference", "Main")))

Just change the filename, the instances of the word “Object” and “Non-Object” to whatever labels you want, and you’ll be good to go. The initial file format here is that the first two columns are amplitude values for each of two conditions, a numeric column indicating which timepoint each row is from, and a numeric column indicating which Subject the row is from. The order of columns in the file doesn’t really matter, though - just make sure you give them the right names when you import them.

I’m sure the code can be made much more efficient, but this was pretty easy to put together with a little practice!

Matt Craddock

I'm a research software engineer

comments powered by Disqus