Week 11: Shiny Part III
Meeting Date: April 3, 2023.
Last updated: 2023-04-10 13:53:29
Timezone: America/Los_Angeles
Class Plan
- AMA
- Shiny Overview
- Shiny, Part III
Slides:
Homework
The ninth assignment is rolled into the creation of a shiny application.
Unifying it All Together with Shiny
Working through these chapters
Start with:
library(shiny)
library(dplyr)
ui <- ...
server <- ...
shinyApp(ui, server)
and the steps will fill in a ui
and server
Chapter 12
tidy
evaluation
- Passing variable names
library(shiny)
library(dplyr)
ui <- fluidPage(
selectInput("var", "Sort by", choices = names(mtcars)),
checkboxInput("desc", "Descending order?"),
tableOutput("data")
)
server <- function(input, output, session) {
sorted <- reactive({
if (input$desc) {
arrange(mtcars, desc(.data[[input$var]]))
} else {
arrange(mtcars, .data[[input$var]])
}
})
output$data <- renderTable(sorted())
}
shinyApp(ui, server)
- The importance of
req
. What does it do?
Chapter 13
Why reactivity?
Playing with Reactive
Excel is Reactive, That’s Why It is Popular
It started with VisiCalc…
Chapter 14
The reactive graph is worth playing with. Due to modern defaults in RStudio, the workflow is a bit tricky. We will have to run the app in the console.
Run it and close it to get this.
Chapter 15
Reactives, single and plural
- An oddity
Pay very close attention to 15.3 on observe
versus observeEvent
. The example in 16.3.3…
library(shiny)
reactiveConsole(TRUE)
x <- reactiveVal(1)
y <- observe({
x()
observe(print(x()))
})
x(2)
x(3)
x(2)
- On Isolate
Isolate is not all that common because the behavior is embedded in two common tools:
15.5 on timing
15.5.2 and the importance of timing. Using on.exit
Chapter 16: Escaping the Graph
The Case Studies
Two that are related.
The timer
Warnings:
It is quite easy to get carried away and muddle the flow.
Readings:
- Mastering Shiny and we want chapters 13 through 16.