I am Margaret Siple (I go by Megsie) and I work at NOAA's Alaska Fisheries Science Center in the Groundfish Assessment Program. I live in Beacon Hill with two cats, Molly and Loki.
Many components of this work were made possible by public resources, including 18F.
Image: Jeff Moore
FISH 549 learning goals
Using GitHub
Documenting data
Using SQL to query databases
Writing unit tests
Creating packages and writing unit tests
Using Markdown to create documentation
GAP Activities
✅ We use GH daily, including to plan survey deployment
✅Documenting data is the story of our lives
✅We store bottom trawl survey data in a SQL database
✅Interior and public packages use unit tests and CI (e.g., coldpool
)
✅We use Markdown for software dx, reproducible reports(Bering Sea, Gulf of Alaska/Aleutian Islands), and more
Photo: Shaya Lyon
Each musician has areas where they’re very specialized, and areas where they are clueless
Each musician has areas where they’re very specialized, and areas where they are clueless
What we do is a combination of highly technical skilled work, creativity and multitasking
Each musician has areas where they’re very specialized, and areas where they are clueless
What we do is a combination of highly technical skilled work, creativity and multitasking
We’re all working together to try to make a big, beautiful thing happen
1) Best available science (+ reproducibility)
2) Well-defined pathways for implementing advice
3) Trust and communication between researchers and stakeholders
1) Best available science (+ reproducibility)
2) Well-defined pathways for implementing advice
3) Trust and communication between researchers and stakeholders
shiny
basics - when to use it, what it's good forshiny
basics - when to use it, what it's good for
How to make an app
shiny
basics - when to use it, what it's good for
How to make an app
Lessons learned from developing a Shiny app for management advice
shiny
basics - when to use it, what it's good for
How to make an app
Lessons learned from developing a Shiny app for management advice
If you want practice or you learn well from hands-on examples, check out https://github.com/mcsiple/shinyoverview
shiny
basics - when to use it, what it's good for
How to make an app
Lessons learned from developing a Shiny app for management advice
If you want practice or you learn well from hands-on examples, check out https://github.com/mcsiple/shinyoverview
There are many other things available in the repo that we won't cover today, but examples are included so you can try them on your own:
Live-translating your Shiny apps into other languages using
{shiny.18n}
Using Shiny to teach remotely with
{learnr}
Generating Markdown reports from Shiny
When we want to make R code accessible outside of an R or RStudio environment. For example,
When we want to make R code accessible outside of an R or RStudio environment. For example,
When we want to make R code accessible outside of an R or RStudio environment. For example,
teaching people how to use a package
giving non-experts a way to "get to know" models and data
When we want to make R code accessible outside of an R or RStudio environment. For example,
teaching people how to use a package
giving non-experts a way to "get to know" models and data
streamlining certain code-intensive activities (like summarizing and communicating simulation outputs)
Shiny can be a little gnarly at first.
Install shiny:
install.packages("shiny")
From The RStudio IDE, pick New File -> Shiny Web App
You can choose between single (app.R) or multiple files (ui.R and server.R)
Does it matter which one you choose?
Not really. Some like the organization of having multiple files 🤷
The ui
(user interface) object dictates the appearance of the app. For something to appear in your app, it needs to be in the UI. UI functions write HTML.
If you put in the console:
shiny::titlePanel("Here is a title")
It returns this html:
<h2>Old Faithful Geyser Data</h2>
The ui
(user interface) object dictates the appearance of the app. For something to appear in your app, it needs to be in the UI. UI functions write HTML.
If you put in the console:
shiny::titlePanel("Here is a title")
It returns this html:
<h2>Old Faithful Geyser Data</h2>
The server()
function contains rendering expressions that create the objects to display.
The server function and UI object are passed to the shinyApp()
function to create a Shiny app object.
The ui looks like this (the "interactive" part is highlighted):
ui <- fluidPage( titlePanel("Old Faithful Geyser Data"), sidebarLayout( sidebarPanel( sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30)), mainPanel( plotOutput("distPlot")) ))
The corresponding ui looks like this:
The ui code contains the following information:
The UI type
fluidPage()
puts elements in rows that can include columns 🍰navbarPage()
has a navigation bar 📁Layout elements (sidebarLayout()
etc.)
Theme information (e.g., {shinythemes}
)
The ui code contains the following information:
The UI type
fluidPage()
puts elements in rows that can include columns 🍰navbarPage()
has a navigation bar 📁Layout elements (sidebarLayout()
etc.)
Theme information (e.g., {shinythemes}
)
Output objects (plotOutput()
, etc.)
Input objects (sliderInput()
,fileInput()
etc.) - also called "widgets"
Input objects link the UI to R code that runs on the server.
The server builds a list-like object called output
. The contents of output
can be displayed in the ui.
server <- function(input, output) { output$distPlot <- renderPlot({ # generate bins based on input$bins from ui.R x <- faithful[, 2] bins <- seq(min(x), max(x), length.out = input$bins + 1) # draw the histogram with the specified number of bins hist(x, breaks = bins, col = 'darkgray', border = 'white') })}
The server builds a list-like object called output
. output
objects are displayed in the ui. Here is how they are linked:
server <- function(input, output) { output$distPlot <- renderPlot({ # generate bins based on input$bins from ui.R x <- faithful[, 2] bins <- seq(min(x), max(x), length.out = input$bins + 1) # draw the histogram with the specified number of bins hist(x, breaks = bins, col = 'darkgray', border = 'white') })}
ui <- fluidPage( titlePanel("Old Faithful Geyser Data"), sidebarLayout( sidebarPanel( sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30)), mainPanel( plotOutput("distPlot")) ))
R code... mostly 😜
R code... mostly 😜
renderPlot()
, renderTable()
, etc.)Rendering functions (renderPlot()
, renderTable()
, etc.)
Reactive expressions are "lazy" - they don't execute unless they are specifically called to do something.
reactive()
caches reactive objects so you can access them later in the server logic -- very important!eventReactive()
creates reactive objects but only when a specific input changes (e.g., a "Fit this model!" button is clicked)Rendering functions (renderPlot()
, renderTable()
, etc.)
Reactive expressions are "lazy" - they don't execute unless they are specifically called to do something.
reactive()
caches reactive objects so you can access them later in the server logic -- very important!eventReactive()
creates reactive objects but only when a specific input changes (e.g., a "Fit this model!" button is clicked)Observe expressions are "eager" - they automatically execute when their dependencies change. Expressions like observe()
can:
mmrefpoints
and its Shiny toolShiny defaults are not the most intuitive / appealing / accessible version they can be.
Shiny defaults are not the most intuitive / appealing / accessible version they can be.
If you are designing an app for management, a good UI is essential.
Shiny defaults are not the most intuitive / appealing / accessible version they can be.
If you are designing an app for management, a good UI is essential.
Shiny defaults are not the most intuitive / appealing / accessible version they can be.
If you are designing an app for management, a good UI is essential.
my #1 tip: if you have time, pilot test with subject matter experts AND users
use UX resources if they are available!
Shiny defaults are not the most intuitive / appealing / accessible version they can be.
If you are designing an app for management, a good UI is essential.
my #1 tip: if you have time, pilot test with subject matter experts AND users
use UX resources if they are available!
if your institution doesn't have UX resources, design pilot testing so that you get helpful feedback on UX:
UX = user experience.
📧: margaret.siple@noaa.gov ☁️: @mcsiple on BlueSky
Mastering Shiny by Hadley Thee Wickham
Colin Fay has several talks on Shiny app workflow and production
We love a cheatsheet
Put emoji in your GitHub commits by using the ::
syntax, e.g.,
git commit -m this code is still growing :seedling:
Emoji options at gitmoji.dev
Slides created using the R package xaringan.
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |