Day 23
Carleton College
Stat 220 - Spring 2026
Every Shiny app has a webpage that the user visits,
and behind this webpage there is a computer that serves this webpage by running R.

When running your app locally, the computer serving your app is your computer.

When your app is deployed, the computer serving your app is a web server.


Shiny graphs need to be “connected” to RStudio or an Rstudio server
plotly isn’t changing the underlying data set/stats being displayed, can be displayed on webpage without an RStudio session
Option 1: Embed a shiny plot/table in HTML docs
runtime: shiny to your YAML headerOption 2: Can create an app.R file with a ui() and server() function
File > New File > Shiny Web App...User interface (ui) controls the layout and appearance of app (generates what the human sees and interacts with)
Server function (server) contains instructions needed to build app (tells the computer/server what to do with the “instructions” the human inputs into the UI)
shinyApp assembles the app and is what tells R that the code we wrote is intended to be a shiny app - make sure this line of code is at the end of your document
Contains everything you see in the app
Inputs that allow the user to interact with the app
outputs generated by the app in different formats (text, tables, charts, images, etc.)
Also controls where inputs and outputs appear on the page
Creates the outputs that appear on the page
Uses a set of instructions written via R functions and commands
Recall that outputs update automatically when we change input values in the UI
This is due to a concept known as reactivity (more later)
File > New File > Shiny Web App... to open the shiny app templateDone in ui
sliderInput() - slider input widget
selectInput() - list of options to select from
textInput() - box to input text
Many more options here
As seen, many types of inputs can be made using particular input functions
All input controls in shiny have two main parameters
inputId - must be unique
label - technically optional, but is what the user sees when interacting with that input in your app
Other parameters depending on exact input function
Done in ui - these functions do not build outputs, they only create placeholders and indicate what type of output they will be (e.g. plot, table, text)
UI output functions
textOutput()
plotOutput()
tableOutput()
and more
The outputId of these functions will be a character string that you specify (and that the server will call)
Server builds output objects via three steps:
Takes in input values defined by ui (ui inputs all appear in input list - access via input$inputId)
Generates output using rendering function (e.g. renderPlot(), renderText(), etc.)
Saves outputs in the outputs list - output$object_name - object_name should match the outputId written in the ui code that creates output placeholders
___Input() and ___Output() functions are used in the ui?render___() function is used to generate the output?When you change input in the UI (e.g. changing the number of bins for the geyser histogram), the output changes automatically
This is thanks to the render___() functions - called reactive functions
Other reactive functions
Reactive functions are followed by ({})
All objects created inside reactive functions are reactive objects
When we call a reactive object later, we must put a pair of parentheses () after it
Not always relevant, but appears frequently when subsetting data based on user input, or whenever code is duplicated for multiple outputs

print(input$a) know when to change?



To reduce duplication, we can create a reactive expression for the data selected
Shiny apps need to be “connected” to RStudio or a remote RStudio server
You can deploy shiny apps online
Make sure that your app lives in its own folder and there are no other .R, .qmd, or .rmd files in that folder. The folder is what gets deployed.
selectInput() in the ui and modify the hist() code in the server so that this input is used in place of darkgraytextInput() that allows users to change the title of the histogram to whatever they specifyfaithful dataset contains a duration column as well. Add a second input and output to visualize the duration of eruptions.