2.2 Shiny

Shiny is a web application framework for R that can help turn your analyses into interactive web applications.

  • No HTML, CSS, or JavaScript knowledge required

Why Shiny?

  • Easy to learn, easy to use.
  • The development time is minimized.
  • Excellent tool for data visualization.
  • Have very strong backing: the R language
  • Fun & Cool.

A Shiny app usually contains two parts:

  1. UI: controls the outlook of the web page
  2. Server: (a live R session) controls the logic

How does Shiny app work?

The “Server” keeps monitoring the UI. Whenever there is a change in the UI, the “Server” will follow some instructions (run some R code) accordingly and update the UI’s display. (This is the basic idea of reactive expression, which is an distinguish feature of Shiny we will talk about later.)

Example

library(shiny)
runExample("01_hello") # a histogram

In the example above, the “Server” keeps monitoring the “slider” in the page, and whenever there is a change with it, the “Server” will re-execute a block of R code to regenerate the hitogram.