03:00
Day 24
Carleton College
Stat 220 - Spring 2025
Start by opening 24-reactivity.R
the number of bootstrap resamples?
the number of histogram bins?
the confidence level?
03:00
Discuss your answers to Part 1 with your group and be ready to report back.
Read through the code in the renderPlot()
and renderPrint()
reactive expressions. Note the key tasks executed within each.
Based on your answers to #4, Is there any replication? That is, are any key tasks executed multiple times? Record your group’s answers and be ready to report back.
04:00
# app.R
library(shiny)
ui <- fluidPage(
headerPanel("basic app"),
sidebarPanel(
sliderInput("a",
label = "Select an input to display",
min = 0, max = 100, value = 50)
),
mainPanel(h1(textOutput("text")))
)
server <- function(input, output) {
output$text <- renderText({
print(input$a)
})
}
shinyApp(ui = ui, server = server)
DOESN’T mean: print the value and send it to the browser
DOES mean: this code is the recipe that should be used to print the output
input$a
changes, use this recipeprint(input$a)
know when to change?Two definitions:
Reactive expression: only runs the first time it is called and then it caches its result until it needs to be updated
create a reactive expression by wrapping a block of code in reactive({...})
use a reactive expression by calling it like a function
To reduce duplication, we can create a reactive expression for the data selected
Complete tasks 6-9 in groups of ~3.
10:00
Shiny apps need to be “connected” to RStudio or a remote RStudio server
You can deploy shiny apps online