building interactive web app with shiny

Download Building interactive web app with shiny

Post on 29-Nov-2014




0 download

Embed Size (px)


It is a talk given by Vivian Zhang, CTO of SupStat Inc which is a leading Data Analytic consulting firm based in New York City, Shanghai and Beijing. NYC Open Data meetup are honored to host this event on Mar 24th,2014. You can find more information at and


  • 1. BuildingInteractiveWebAPPwithShiny Supstat Inc.
  • 2. Outline Introduction to shiny Main functions of shiny Advanced features of shiny Share APP with others Case study 2/30
  • 3. Introduction to shiny 3/30
  • 4. Whybuildwebapplication R is great, and the Internet is great. Everyone has a browser. Communicate your results dynamically. Create custom analytics tools to explore data. 4/30
  • 5. Introductiontoshiny Open Sourced by RStudio November 2012 Not the first to get R in the browser (rApache, Rserve, Rook) Default widgets and settings make it easy to generate apps Don't need to know HTML, CSS and javascript to get started Twitter Bootstrap for default UI - looks good Web sockets for communication between client and server Reactive Programming model Works on Windows, Mac, Linux 5/30
  • 6. Introductiontoshiny Ready to use shiny Install R from CRAN Useful to have Chrome, Firefox, Safari... Rstudio or other texteditor Install Shiny using R command: install.packages("shiny") 6/30
  • 7. Asimpleexample library(shiny) runExample("01_hello") 7/30
  • 8. Asimpleexample Web Application Layout 8/30
  • 9. Asimpleexample Web Application Layout 9/30
  • 10. ui.R:ControlsthelookoftheApp library(shiny) #DefineUIforapplicationthatplotsrandomdistributions shinyUI(pageWithSidebar( #Applicationtitle headerPanel("HelloShiny!"), #Sidebarwithasliderinputfornumberofobservations sidebarPanel( sliderInput("obs", "Numberofobservations:", min=0, max=1000, value=500) ), #Showaplotofthegenerateddistribution mainPanel( plotOutput("distPlot") ) )) 10/30
  • 11. server.R:SpecifieswhatRisdoing #Defineserverlogicrequiredtogenerateandplotarandomdistribution shinyServer(function(input,output){ #Expressionthatgeneratesaplotofthedistribution.Theexpression #iswrappedinacalltorenderPlottoindicatethat: # # 1)Itis"reactive"andthereforeshouldbeautomatically # re-executedwheninputschange # 2)Itsoutputtypeisaplot # output$distPlot