Shiny Dashboards
Welcome

Colin Rundel

Shiny Dashboards

Welcome!

Wifi: Posit Conf 2023
Password: conf2023

pos.it/dashboard-conf23

Welcome

Instructor


Colin Rundel

Associate Professor of the Practice

Department of Statistical Science

Duke University

rundel.github.io

Instructor

Garrick Aden-Buie

Software Engineer
Data Science Educator
Shiny at Posit

garrickadenbuie.com

Teaching Assistants

  • Maya Gans

  • Katherine Simeon

Introduce yourself

We wont go around the room, but take the next couple of minutes to introduce yourself to your neighbors.

Some suggested topics,

  • Name

  • Where you are coming from

  • Why you are interested in learning Shiny

05:00

Workshop materials



Schedule (roughly)

Time Activity
09:00 - 09:30 Welcome
09:30 - 10:30 flexdashboard
10:30 - 11:00 Coffee break
11:00 - 12:30 flexdashboard
12:30 - 13:30 Lunch break
13:30 - 15:30 Shinydashboard / bslib
15:00 - 15:30 Coffee break
15:30 - 17:00 Theming / Publishing / Wrap-up

WiFi



Username: Posit Conf 2023

Password: conf2023

Code of Conduct

All details are available at https://posit.co/code-of-conduct/. Please review them carefully.

You can report Code of Conduct violations in person (any posit::conf staff ), by email (codeofconduct@posit.co), or by phone (844-448-1212). Please see the policy linked above for contact information.

Other useful info

  • There are gender-neutral bathrooms located are among the Grand Suite Bathrooms.

  • There are two meditation/prayer rooms: Grand Suite 2A and Grand Suite 2B.

    • Open Sunday - Tuesday 7:30 a.m. - 7:00 p.m., Wednesday 8:00 a.m. - 6:00 p.m.
  • The lactation room is located in Grand Suite 1.

    • Open Sunday - Tuesday 7:30 a.m. - 7:00 p.m., Wednesday 8:00 a.m. - 6:00 p.m.
  • Participants who do not wish to be photographed have red lanyards; please note everyone’s lanyard colors before taking a photo and respect their choices.

Asking for help (Stickies)

I’m stuck

I’m working

I’m done


I have a general question

Other communication (Discord)

Go posit.co/conference, click Login. Once you’ve logged in there’s large image to connect you to the conference Discord server.

This workshop has a private channel under Workshops,

#shiny-dashboards

This is a great place to ask questions, post resources, memes, or most anything else before, during, and after the workshop.

Computational Environment

Posit Cloud

You can use the following link to join the workshops Posit Cloud space,

Once you have joined you can then select the shiny-dashboard assignment,

This creates a copy of all materials and launches a cloud session for you.

Cloud session

If everything is working you should see something very close to the following,

File organization

Project root:

  • slides/ - all slides and related materials

  • demos/ - sample code for each demo

  • exercises/ - starter code for each exercise

  • exercises/solutions/ - sample solution code for each exercise

  • data/ - example data sets used in demos and exercises

A starting point

Data

(d = read_csv("data/weather.csv"))
# A tibble: 1,344 × 25
   city   state region time                 temp feelslike
   <chr>  <chr> <chr>  <dttm>              <dbl>     <dbl>
 1 Chica… Illi… Midwe… 2023-09-11 05:00:00  69.8      69.8
 2 Chica… Illi… Midwe… 2023-09-11 06:00:00  69.4      69.4
 3 Chica… Illi… Midwe… 2023-09-11 07:00:00  70.6      70.6
 4 Chica… Illi… Midwe… 2023-09-11 08:00:00  70        70  
 5 Chica… Illi… Midwe… 2023-09-11 09:00:00  68.4      68.4
 6 Chica… Illi… Midwe… 2023-09-11 10:00:00  65        65  
 7 Chica… Illi… Midwe… 2023-09-11 11:00:00  61.8      61.8
 8 Chica… Illi… Midwe… 2023-09-11 12:00:00  62.3      62.3
 9 Chica… Illi… Midwe… 2023-09-11 13:00:00  63        63  
10 Chica… Illi… Midwe… 2023-09-11 14:00:00  64.2      64.2
# ℹ 1,334 more rows
# ℹ 19 more variables: humidity <dbl>, dew <dbl>,
#   precip <dbl>, precipprob <dbl>, snow <dbl>,
#   snowdepth <dbl>, windgust <dbl>, windspeed <dbl>,
#   winddir <dbl>, pressure <dbl>, visibility <dbl>,
#   cloudcover <dbl>, solarradiation <dbl>,
#   solarenergy <dbl>, uvindex <dbl>, severerisk <dbl>, …

Demo 01 - A starter app

demos/demo01.R

library(tidyverse)
library(shiny)

ggplot2::theme_set(ggplot2::theme_bw())

d = readr::read_csv(here::here("data/weather.csv"))

d_vars = d |>
  select(where(is.numeric)) |>
  names()

shinyApp(
  ui = fluidPage(
    titlePanel("Weather Forecasts"),
    sidebarLayout(
      sidebarPanel(
        selectInput(
          "city", "Select a city",
          choices = c("Chicago", "Durham", "Sedona", "New York", "Los Angeles")
        ),
        selectInput(
          "var", "Select a variable",
          choices = d_vars, selected = "temp"
        )
      ),
      mainPanel( 
        plotOutput("plot"),
        tableOutput("minmax")
      )
    )
  ),
  server = function(input, output, session) {
    
    d_city = reactive({
      d |>
        filter(city %in% input$city)
    })
    
    output$plot = renderPlot({
      d_city() |>
        ggplot(aes(x=time, y=.data[[input$var]], color=city)) +
        ggtitle(input$var) +
        geom_line()
    })
    
    output$minmax = renderTable({
      d_city() |>
        mutate(
          day = lubridate::wday(time, label = TRUE, abbr = FALSE),
          date = as.character(lubridate::date(time))
        ) |>
        group_by(date, day) |>
        summarize(
          `min` = min(.data[[input$var]]),
          `max` = max(.data[[input$var]]),
          .groups = "drop"
        )
    })
  }
)

Your turn - Exercise 01

Using the code in exercises/ex01.R (same as the previous slide) try running the app in Posit cloud.

Check that you are able successfully run the shiny app and are able to interact with it.

If everything is working try modifying the code:

  • Can you rearrange the elements of the mainPanel() to make things more readable?

  • What would we need to change to allow for multiple cities to be selected and visualized?

05:00