Quarto Dashboards
To create a dashboard you need to use format: dashboard
in the YAML:
---
title: "Palmer Penguins"
author: "Allison Theobold"
format: dashboard
---
# Bills
```{r}
```
# Flippers {orientation="columns"}
## Column
```{r}
```
```{r}
```
## Column
```{r}
```
What orientation will the Bills
page use?
are created by adding the .tabset
class to a row or column.
## Column - Medals by country {width=35%}
### Row - Value boxes {height=30%}
```{r}
#| label: summer-calculate-most-medals
summer_most_golds <- summer_olympics |>
filter(medal == "Gold") |>
count(team, sort = TRUE) |>
slice_head(n = 1)
summer_most_silvers <- summer_olympics |>
filter(medal == "Silver") |>
count(team, sort = TRUE) |>
slice_head(n = 1)
summer_most_bronzes <- summer_olympics |>
filter(medal == "Bronze") |>
count(team, sort = TRUE) |>
slice_head(n = 1)
```
::: {.valuebox icon="award-fill" color="#d4af37"}
Most golds:
`{{r}} summer_most_golds$n`
`{{r}} summer_most_golds$team`
:::
::: {.valuebox icon="award-fill" color="#c0c0c0"}
Most silvers:
`{{r}} summer_most_silvers$n`
`{{r}} summer_most_silvers$team`
:::
::: {.valuebox icon="award-fill" color="#cd7f32"}
Most bronzes:
`{{r}} summer_most_bronzes$n`
`{{r}} summer_most_bronzes$team`
The format of interactive dashboards are similar to a “standard” dashboard. The difference lies in how the outputs (e.g., plots, tables) are created.
The user is given a set of controls that influence the output that is seen.
There are code chunks that “react” to these user inputs.
The outputs displayed depend on these user inputs.
There are three main #| context:
values that code chunks can have: data
, setup
, and server
.
#| context: setup
This could have been broken apart into two code chunks, one with a setup
context and one with a data
context. Using the data
context is helpful because any R objects created in that chunk will be saved to an .RData file, which will then be loaded during Shiny server startup.
.sidebar
Contentdashboard.qmd
---
title: "Diamonds Explorer"
author: "Barkamian Analytics"
format: dashboard
server: shiny
---
```{r}
#| context: setup
library(ggplot2)
dataset <- diamonds
```
# {.sidebar}
```{r}
sliderInput('sampleSize', 'Sample Size',
min = 1, max = nrow(dataset),
value = min(1000, nrow(dataset)),
step = 500, round = 0)
br()
checkboxInput('jitter', 'Jitter')
checkboxInput('smooth', 'Smooth')
```
```{r}
selectInput('x', 'X', names(dataset))
selectInput('y', 'Y', names(dataset), names(dataset)[[2]])
selectInput('color', 'Color', c('None', names(dataset)))
```
```{r}
selectInput('facet_row', 'Facet Row',
c(None = '.', names(diamonds[sapply(diamonds, is.factor)])))
selectInput('facet_col', 'Facet Column',
c(None = '.', names(diamonds[sapply(diamonds, is.factor)])))
```
'sampleSize'
: the name of the object that stores the value (to be used later in other code chunks)'Sample Size'
: the title (for the slider) that is displayed on the dashboardmin = 1
: the starting value of the slidermax = nrow(dataset)
: the ending value of the slidervalue = min(1000, nrow(dataset))
: sets the initial (default) value of the sliderstep = 500
: how big of increments should be displayedround = 0
: specifies there should be 0 decimals places usedWhy do these say dataset
instead of diamonds
? This makes the app usable for any dataset!
dashboard.qmd
---
title: "Diamonds Explorer"
author: "Barkamian Analytics"
format: dashboard
server: shiny
---
```{r}
#| context: setup
library(ggplot2)
dataset <- diamonds
```
# {.sidebar}
```{r}
sliderInput('sampleSize', 'Sample Size',
min=1, max=nrow(dataset),
value=min(1000, nrow(dataset)),
step=500, round=0)
br()
checkboxInput('jitter', 'Jitter')
checkboxInput('smooth', 'Smooth')
```
```{r}
selectInput('x', 'X', names(dataset))
selectInput('y', 'Y', names(dataset), names(dataset)[[2]])
selectInput('color', 'Color', c('None', names(dataset)))
```
```{r}
selectInput('facet_row', 'Facet Row',
c(None='.', names(diamonds[sapply(diamonds, is.factor)])))
selectInput('facet_col', 'Facet Column',
c(None='.', names(diamonds[sapply(diamonds, is.factor)])))
```
# Plot
```{r}
plotOutput('plot')
```
# Data
```{r}
tableOutput('data')
```
'plot'
and 'data'
coming from?dashboard.qmd
```{r}
#| context: server
dataset <- reactive({
diamonds[sample(nrow(diamonds), input$sampleSize),]
})
output$plot <- renderPlot({
p <- ggplot(
dataset(),
aes_string(x=input$x, y=input$y)) + geom_point()
if (input$color != 'None')
p <- p + aes_string(color=input$color)
facets <- paste(input$facet_row, '~', input$facet_col)
if (facets != '. ~ .')
p <- p + facet_grid(facets)
if (input$jitter)
p <- p + geom_jitter()
if (input$smooth)
p <- p + geom_smooth()
p
})
output$data <- renderTable({
dataset()
})
```
plotOutput('plot')
is an empty picture frame in your user interface
renderPlot()
is the painting you generate in your server
output$plot
places the painting in the frame