A shiny
Syllabus Module for Week 11
Environments and data.
tidy evaluation
next time
We will walk through at least one example as time permits.
docker build
docker push
This can be tricky with M1 macs as some images do not play nicely. NB: I am just beginning to explore this because it did not occur to me that it would be an issue from my Intel workstation.
Start with:
library(shiny)
library(dplyr)
ui <- ...
server <- ...
shinyApp(ui, server)
and the steps will fill in a ui
and server
tidy
evaluationScreen shot
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)
req
. What does it do?Shot of help
Why reactivity?
Shot
Simple Example
It started with VisiCalc…
The History
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.
Settings
Run it and close it to get this.
reactlog
Reactives, single and plural
Two types
Behavior is a bit different
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)
Isolate is not all that common because the behavior is embedded in two common tools:
part 1 - invalidateLater
part 2 - Details
on.exit()
15.5.2 and the importance of timing. Using on.exit
Two that are related.
The timer
It is quite easy to get carried away and muddle the flow.
Anti-patterns
Shot of Final Section
Communicating With Data: Week 11 (3 Apr 2023)