Dynamic Data Science Reporting with R

Josh Oberman
Inquidia Consulting

R

  • Programming Language For Statistical Computing
  • Open Source, Multi-Paradigm
  • Robust package ecosystem
  • Premier Programming Language for Data Science

Shiny

  • R Package that allows for the creation of data driven applications
  • Build apps in R without having to know HTML or CSS
  • Built on bootsrap CSS template, renders well on all devices
  • Use R as the backend and get a lot of UI for free

Shiny and HTML

  • All HTML elements become R functions
  • e.g. <p>Some Text</p> becomes 'p(SomeText)'
  • Many default HTML layouts such as "pageWithSideBar", so we don't have to worry about playing with it too much
  • Add custom html tags to embed iframes, create divs, etc
  • Use custom bootstrap css templates
  • Layout page using "fluidPage()" function, divides page as dictated by bootstrap

Elements of a Shiny Program

  • Two R scripts: ui.R and server.R
  • Client and Server side
  • ui.R creates layout of app
  • server.R does all the heavy lifting
  • Variables defined in ui.R are available in list 'input' for server.R
  • Variables defined in server.R are available in list 'output' for ui.R

Reactive Programming

  • Core feature of shiny
  • Removes any need to hard code event handlers
  • Essential idea is change in input -> change in output
  • Only works inside 'reactive({})' functions on server side
  • reactive function will only execute the code inside it
  • Variables defined in reactive contexts can only be accessed in other reactive contexts
  • Functions used to render UI elements are also reactive

Example

Many Widgets

Deploy shiny apps

  • Shiny Server: RStudio product that allows for deployment of Shiny apps to multiple users
  • Pre-configured web server for your Shiny apps
  • Service shinyapps.io allows for deployment of shiny apps to cloud
  • 2 versions of shiny server: Shiny Server Open and Shiny Server Pro
  • Shiny Server Pro allows you to run multiple R processes, password protect your apps
  • https://joberman.shinyapps.io/chordGenerator/

Make use of fancy new interactive plotting tools

Plotly:

library("knitr")
library("devtools")
## Warning: package 'devtools' was built under R version 3.2.5
url<-"https://plot.ly/~MattSundquist/1971"
plotly_iframe <- paste("<center><iframe scrolling='no' seamless='seamless' style='border:none' src='", url, 
    "/800/1200' width='800' height='1200'></iframe><center>", sep = "")

Plotly

Other interactive libraries

Conclusion

Pros

  • Shiny allows you to harness the full power of R for interactive apps
  • Use machine learning, time series forecasting, clustering and display results in real time
  • Many fancy new R packages allow for interactive plots and other goodies
  • Under very active development

Cons

  • R is a slow language
  • Documentation can sometimes be shoddy
  • Questions remain about large scale deployment