Shiny Apps for Communicating Science
Contents
Shiny Apps Overview
What are Shiny Apps?
What are Shiny Apps?
Why?
Why?
Shiny App Anatomy
the basics
Shiny App Anatomy
the basics
User Interface
(UI)
Server
Shiny App Anatomy
the basics
User Interface
(UI)
Server
inputs
outputs
Shiny App Anatomy
the basics
User Interface
(UI)
Server
inputs
outputs
“front-end”
“back-end”
lists
app.R
ui <- fluidPage( �� widgetInput(“id”),
somethingOutput(“id”)
)
server <- function(input, output){ �
dataset <- reactive(input$id)�� output$id <- renderSomething()
}
app.R
ui <- fluidPage( �� widgetInput(“id”),
somethingOutput(“id”)
)
server <- function(input, output){ �
dataset <- reactive(input$id)�� output$id <- renderSomething()
}
app.R
ui <- fluidPage( �� widgetInput(“id”),
somethingOutput(“id”)
)
server <- function(input, output){ �
dataset <- reactive(input$id)�� output$id <- renderSomething()
}
app.R
ui <- fluidPage( �� sliderInput(“years”),
plotOutput(“plot”)
)
server <- function(input, output){ �
dataset <- reactive(input$years)�� output$plot <- renderPlot(dataset)
}
Shiny App Anatomy - server
Shiny App Anatomy - server
similar to R scripting as you know it, but with ✨ reactivity ✨
Shiny App Anatomy - server
similar to R scripting as you know it, but with ✨ reactivity ✨
reactivity allows inputs and outputs to talk to each other
Shiny App Anatomy - server
similar to R scripting as you know it, but with ✨ reactivity ✨
reactivity allows inputs and outputs to talk to each other
requires comfort in functional programming
Shiny App Anatomy - server
✨ reactivity ✨
Shiny App Anatomy - server
✨ reactivity ✨
“downstream” features automatically adapt to “upstream” changes
can respond to specific cues, or ambient changes in environment
Shiny App Anatomy - server
✨ reactivity ✨
input
output
Shiny App Anatomy - server
✨ reactivity ✨
input
output
input
Shiny App Anatomy - server
✨ reactivity ✨
input
output
input
output
Shiny App Anatomy - server
✨ reactivity ✨
input
reactive
output
input
output
Shiny App Anatomy - server
✨ reactivity ✨
input
reactive
output
input
output
output
✨ reactivity ✨, an example:
input
output
input$selected_islands <-
checkboxGroupInput(...)
output$plot <- renderPlot({
filtered_data <- data %>%
filter(island %in% input$selected_islands)
ggplot(filtered_data)
})
✨ reactivity ✨, an example:
input
output
input$selected_islands <-
checkboxGroupInput(...)
output$plot <- renderPlot({
filtered_data <- data %>%
filter(island %in% input$selected_islands)
ggplot(filtered_data)
})
each time input is changed, R is doing 2 things:
✨ reactivity ✨, an example:
input
output
input$selected_islands <-
checkboxGroupInput(...)
output$plot <- renderPlot({
plotdata <- data %>%
filter(island %in% input$selected_islands)
ggplot(plotdata)
})
output 2
output$table <- rendertable({
tabledata <- data %>%
filter(island %in% input$selected_islands)
table(tabledata)
})
✨ reactivity ✨, an example:
input
output
input$selected_islands <-
checkboxGroupInput(...)
output$plot <- renderPlot({
plotdata <- data %>%
filter(island %in% input$selected_islands)
ggplot(plotdata)
})
output 2
output$table <- rendertable({
tabledata <- data %>%
filter(island %in% input$selected_islands)
table(tabledata)
})
each time input is changed, R is doing 4 things:
✨ reactivity ✨, an example:
input
output
input$selected_islands <-
checkboxGroupInput(...)
output$plot <- renderPlot({
ggplot(reactivedata()))
})
output 2
output$table <- rendertable({
table(reactivedata())
})
reactive
reactivedata <- reactive({
data %>%
filter(island %in%
input$selected_islands)
})
✨ reactivity ✨, an example:
input
output
input$selected_islands <-
checkboxGroupInput(...)
output$plot <- renderPlot({
ggplot(reactivedata()))
})
output 2
output$table <- rendertable({
table(reactivedata())
})
reactive
reactivedata <- reactive({
data %>%
filter(island %in%
input$selected_islands)
})
using reactives limits operations:
Shiny App Anatomy - server
✨ reactivity ✨
Type of Reactivity | Functions | Common uses |
reactive object | reactive(), reactiveVal(), reactiveValues(), render___() | continuously updating datasets based on user input |
reactive action | observe() | completing a task, rather than creating an object (does not yield output) |
response | observeEvent(), eventReactive() | responses to action buttons, |
Shiny App Anatomy - ui
Shiny App Anatomy - ui
Shiny App Anatomy - ui
Widgets allow users to interact with apps!
Shiny App Anatomy - ui
Shiny App Anatomy - ui
sidebar panel
main panel
title panel
Shiny App Anatomy - ui
Shiny App Anatomy - ui
dashboard sidebar
dashboard body
dashboard header
box
Shiny App Anatomy - ui
Shiny App Anatomy - ui
Shiny App Anatomy - folder structure
.Rproj
App1
app.R
App2
app.R
App3
ui.R
server.R
App4
app.R
www
style.css
data.rds
other extras
pause to view examples 1-3
Shiny affiliates for full interactivity
Shiny affiliates for full interactivity
You may know:
You may benefit from:
Shiny affiliates for full interactivity
You may know:
You may benefit from:
Shiny affiliates for full interactivity
You may know:
You may benefit from:
Shiny affiliates for full interactivity
You may know:
You may benefit from:
See app_8_upgrade_your_skills for examples
Shiny for communication
Shiny for communication
interactivity allows users to view datasets more closely than they otherwise could
Shiny for communication
interactivity allows users to view datasets more closely than they otherwise could
user-generated report generation through Parameterized R Markdowns
(sending shiny inputs and reactives to embedded rmd scripts).
Shiny for communication
interactivity allows users to view datasets more closely than they otherwise could
user-generated report generation through Parameterized R Markdowns
(sending shiny inputs and reactives to embedded rmd scripts).
see example 5: https://github.com/jakelawlor/Shiny_App_Tutorial
Deploying Shiny Apps
Deploying Shiny Apps
Deploying Shiny Apps
Deploying Shiny Apps
Deploying Shiny Apps
as files
as urls
in summary, shiny apps offer:
in summary, shiny apps offer:
web development without actually having to know web development
communication directly to collaborators / stakeholders
customized data viewing and report generation
questions?
catwalk?