September 28, 2017 @ INRA/Jouy en Josas Bioinformatics Day

Interactivity in data analysis

Why?

  • Deeper exploration of data than static plots (zoom, highlight relevant data points, hide irrelevant data)
  • Immediate feedback on how data/figures/results change when inputs are modified
  • User becomes an active participant in the analysis
  • Exploratory analysis, teaching, reporting

A word of caution: if the interactivity doesn’t add anything to your visualization, don’t do it!

Interactivity in R

Recent explosion in tools for interactive visualizations in R:

  • networkD3: Interactive network graphs with d3
  • leaflet: add layers on top of maps
  • googleVis: use Google Chart tools from R
  • htmlwidgets: Javascript visualization libraries in R
  • rCharts: R interface to multiple javascript charting libraries
  • crosstalk: add-on for cross-widget interactions

  • plotly: easily convert ggplot2 figures to interactive plots

What's Shiny?

  • R library that allows you to turn standard R code into interactive web applications
  • Two-way communication: R scripts can be rerun based on inputs from the app
  • Requires server, or running locally in R

Easy interactivity: ggplot → ggplotly

library(tidyverse)
p <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, 
                      color=Species, shape=Species)) + 
  geom_point(size=6, alpha=0.6)
p

Easy interactivity: ggplot → ggplotly

library(plotly)
ggplotly(p, tooltip = c("y", "x"))

Easy interactivity: ggplot → ggplotly

ggplotly(p, tooltip = c("y", "x", "colour"))

Easy interactivity: ggplot → ggplotly

p <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species, 
                      shape=Species, label=Petal.Width)) + 
  geom_point(size=6, alpha=0.6)
ggplotly(p, tooltip = c("y", "x", "colour", "label"))

Easy interactivity: ggplot → ggplotly

p2 <- ggplot(iris, aes(x=Species, y=Sepal.Length, 
                       fill=Species)) +  geom_boxplot() 
p2

Easy interactivity: ggplot → ggplotly

ggplotly(p2)

More specialized interactivity

library(d3heatmap)
d3heatmap(mtcars, scale="column", colors="Blues")

Easy Shiny: Rmarkdown → flexdashboard

Easy Shiny: Rmarkdown → flexdashboard

Easy Shiny: Rmarkdown → flexdashboard

Easy Shiny: Rmarkdown → flexdashboard

Easy Shiny: Rmarkdown → flexdashboard

Easy Shiny: Rmarkdown → flexdashboard

Easy Shiny: Rmarkdown → flexdashboard

Easy Shiny: Rmarkdown → flexdashboard

Easy Shiny: Rmarkdown → flexdashboard

Easy Shiny: Rmarkdown → flexdashboard

Sharing interactive visualizations

  • Standalone HMTL files
  • Host on website
  • Embedded Rmarkdown files
  • Post plotly graphics on plot.ly account (private or public URL)
  • Embedded in Shiny applications
  • F1000 research now allows for (plotly) interactive graphics! https://f1000research.com/articles/6-1396/v1#f6
  • RPubs: Publish directly from RStudio

Sharing interactive Shiny apps

  • Share the raw files for your Shiny app (.Rmd or ui.R + server.R files): requires user to have R/Shiny installed on their own computer and access to relevant data files
library(shiny)
runApp("...")
runURL("...")
runGitHub("...")

Sharing interactive Shiny apps

  • Share Shiny app as a webpage: most user-friendly, local installation of R not required, app navigation through web browser

    • Web hosting yourself
    • Shinyapps.io: RStudio's hosting service with free → starter ($9/month) → basic ($39/month)→ standard ($99/month) → professional ($299/month) plans
      • Free plan limited to 5 apps, 25 active hours/month, no password protection
    • Shiny Server: companion program for Linux servers that builds a web server to host Shiny apps (free, open source)
    • Shiny Server Pro: paid version ($10k/year but 50% off discount for academic institutions) with password authentication, encryption, …

Discussion

  • Lots of recent development in the R community has made it very easy to incorporate interactivity into data analyses

  • Out-of-box tools allow for easy initiation, but many specialized packages exist and lots of customization possible if some knowledge of Javascript, CSS, D3, …

  • Sharing apps is still a bit of a sticking point: depends on intended audience, required computing power, number of expected users, …
    • What could/should INRA's strategy be? How many potential Shiny developers/users at INRA?
    • Invest in a (pro?) Shiny server to be installed on a platform server or an AWS instance with Shiny server?
    • Professional Shinyapps.io plan to be shared among users?

Some references/examples