Lecture 8: Shiny iDataViz Web Apps

HKU STAT3622 Data Visualization by Dr. Aijun Zhang
26-30 October 2017

What's covered in this lecture?

  • Introduction to Shiny
  • Shiny App Structure
  • User Interface
  • Shiny Dashboard
  • R Markdown with Shiny

Introduction to Shiny

  • Shiny is an R package, for easy building interactive web apps straight from R.

  • Linked views of interactive data visualization (compare with plotly)

  • It may enable R Markdown (dynamic documents) to be interactive

  • It provides tools for building dashboards …

  • Seven lessons from https://shiny.rstudio.com/tutorial/

Shiny App Structure


  • ui: control widgets
  • server: renderText, renderTable, renderPlot,

User Interface

Shiny Dashboard

R Markdown with Shiny

  • In Rmd, add “runtime: shiny” in the header

  • R chunk with shinyApp(ui=..., server=...)

  # Define UI elements in the front end
  ui = fluidPage(
    titlePanel("Whatever App Title"),
    sidebarPanel(sliderInput("nbreaks", "Number of breaks:",
                             min = 6, max = 50, value = 20)),
  # Define server logic in the back end
  server = function(input, output) {
    output$thisPlot <- renderPlot({
      hist(iris$Sepal.Length, n=input$nbreaks)
  options = list(height = 500)
  • “Run Document” to generate the report with live Shiny apps