Dashboards

Data at a glance

Last Time

  1. Interpolation splits by area.
  2. Votes are extensive.
  3. SR precincts have shapes.
  4. Two approaches estimate new-map votes.

Key Ideas for Today

  1. A dashboard can be used to monitor and explore data.
  2. Rows and columns lay out cards.
  3. A value box shows one number.
  4. Pages split up a dashboard.

Data Dashboard

An interactive display of selected statistics and plots that lets the user quickly monitor, explore, and understand patterns in data.

Used for:

Tools for Dashboards

Workshop

Anatomy of a Dashboard

Layout

  • Define new row with ## Row, new column with ## Column
  • Nest one inside the other using ### for child (e.g. ### Column)
  • Defaults to row-by-row layout. Change by using
---
format:
  dashboard:
    orientation: columns
---
  • Each code cell with output creates one card
  • Tune dimensions by adding e.g. ## Row {height=30%}

Layout by row

---
format: dashboard
---
    
## Row {height=70%}

```{r}
```

## Row {height=30%}

```{r}
```

```{r}
```

Layout by column

---
format: 
  dashboard:
    orientation: columns
---
    
## Column {width=60%}

```{r}
```

## Column {width=40%}

```{r}
```

```{r}
```

Your turn

  1. Add four code cells at the bottom that each print something (e.g. 1, 2, 3, 4).
  2. Arrange them in a 2 x 2 grid layout.
02:30

Guess the Metaphor

A dashboard is like a magic shop: out of everything in the storeroom (the data), the shopkeeper picks a few prized items and sets each in its own display case (a card), arranged in rows and columns so a customer can take in the whole shop at a glance.

Data Display

Plots

You can insert graphics from ggplot, base R, or an interactive library. It can be helpful to tweak fig-width and fig-height.

## Row {height="65%"}

```{r}
#| fig-width: 10
#| fig-height: 8
plot(cars)
```

## Row {height="35%"}
        
```{r}
#| fig-width: 5
#| fig-height: 4
plot(pressure)
```
    
```{r}
#| fig-width: 5
#| fig-height: 4
plot(airmiles)
```

Tables

  1. Static table: gt::gt(), knitr::kable().
  2. Interactive table: DT::datatable()

kable()

library(knitr)
kable(head(mtcars))
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1

datatable()

library(DT)
datatable(mtcars, options = list(pageLength = 5))

Value boxes

You can create a dynamic value box using the following.

```{r}
#| component: valuebox
#| title: Quakes in the last 24 hours
list(
  icon = "stopwatch",
  color = "primary",
  value = n_24
)
```

Blank Cards

You can create a blank card to fill with anything (code, images, markdown) using:

::: {.card}
Gapminder combines data from multiple sources into
unique coherent time-series that can’t be found
elsewhere. Learn more about the Gapminder dataset at
<https://www.gapminder.org/data/>.
:::

Your Turn

Lay out the earthquake data in your dashboard:

  1. Two columns.
  2. Left column, top row: value boxes for hours_last and n_24.
  3. Left column, bottom row: the table top_n_table.
  4. Right column: quake_map, filling the whole column.
06:00

Pages

Split your dashboard into multiple pages by adding level one headers with the page name. This example uses two pages, “Bills” and “Flippers”, that will be linked in the navbar.

---
title: "Palmer Penguins"
format: dashboard
---
    
# Bills 

```{r}
```

# Flippers

## Column

```{r}
```

```{r}
```

## Column 

```{r}
```

Key Ideas for Today

  1. A dashboard can be used to monitor and explore data.
  2. Rows and columns lay out cards.
  3. A value box shows one number.
  4. Pages split up a dashboard.

For Next Time

  1. Sign up for Quiz 5 (11/2-11/3).
  2. Finish PS 5, due 10/31.
  3. Project Studio 4 is the week of 11/2.