https://uomresearchit.github.io/RSE18-shiny-workshop/
For example:
rstudio
gapminder.rds
contains the gapminder data
workshopFunctions.R
contains the functions we will use.
codeExample.R
shows how to use the plotting functions.
The course website https://uomresearchit.github.io/RSE18-shiny-workshop/ contains all the exercises, links to solutions and more detail than these slides.
mawdsley
folder is a git repositoryworked_example
directory
git checkout 01_defaultapp
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins", ...
),
mainPanel(
plotOutput("distPlot")
)
)
)
input$bins
is a source
output$distPlot
is an endpoint
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')
})
}
Shiny handles the dependencies between sources and endpoints, and only updates what is needed - Reactive programming.
gapminder.rds
) and workshopFunctions.R
to your app directoryModify the app to load the ggplot2 and dplyr libraries, gapminder data, and workshopFunctions.R
Check your app still works
(Course notes: Getting started)
checkboxGroupInput()
widget to select the continents we wish to display on the graphtitlePanel()
to something sensible(This won’t do anything yet - we’ll connect it to the graph shortly)
(Course notes: User interface design)
produceGapminderPlot()
git:04_gapminderplotcodeExample.R
(Course notes: Putting it all together)
Run from R(Studio)
(Course notes: Deploying Shiny apps)
sidebarLayout()
is a good starting point.fluidPage()
layout gives us more control.ui <- fluidPage(
titlePanel("Gapminder visualisation"), # Will cover whole width
plotOutput("gapminderPlot", click = "plotClick"), # Ditto
fluidRow(
column(6, # column width
sliderInput(inputId = "year", ....) # Things to include in the column
),
column(6, # Next column
checkboxGroupInput("continent", ....)# Things to include in second column
)
)
)