Looking further: Building interactive web apps in R + Shiny

Lecture 26

Dr. Mine Çetinkaya-Rundel

Duke University
STA 199 - Fall 2024

December 5, 2024

Warm-up

Announcements

  • Course and TA evaluations due Monday, 12/9

  • Project due at 5 pm today

  • Peer evaluations due at 5 pm tomorrow

Interactive web apps in R with Shiny

Shiny

Shiny is an R package that makes it easy to build interactive web apps straight from R. You can host standalone apps on a webpage or embed them in R Markdown documents or build dashboards. You can also extend your Shiny apps with CSS themes, htmlwidgets, and JavaScript actions.

Shiny App


Server

+


Client / Browser

+ +

Anatomy of an App

library(shiny)

shinyApp(
  ui = list(
    # new (to you) widgets go here
  ),
  
  server = function(input, output, session) {
    # somewhat familiat (to you) code goes here
  }
)

A brief widget tour

rundel.shinyapps.io/widgets/

Live demo

ae-21-weather-forecast

  • Go to your ae project in RStudio.

  • If you haven’t yet done so, make sure all of your changes up to this point are committed and pushed, i.e., there’s nothing left in your Git pane.

  • If you haven’t yet done so, click Pull to get today’s application exercise file: ae-21-weather-forecast.R.

  • Work through the application exercise in class, and render, commit, and push your edits.

Data

Scaffold 1

Find variables that are numeric and not constant for selected city

Scaffold 2

Calculate number of days that mention “Rain”, “Snow”, “Clear” in conditions