Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions inst/examples-shiny/01_hello/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ library(bslib)

# Define UI for app that draws a histogram ----
ui <- page_sidebar(

# App title ----
title = "Hello Shiny!",

Expand All @@ -18,7 +17,6 @@ ui <- page_sidebar(
max = 50,
value = 30
)

),

# Output: Histogram ----
Expand All @@ -27,7 +25,6 @@ ui <- page_sidebar(

# Define server logic required to draw a histogram ----
server <- function(input, output) {

# Histogram of the Old Faithful Geyser Data ----
# with requested number of bins
# This expression that generates a histogram is wrapped in a call
Expand All @@ -37,16 +34,18 @@ server <- function(input, output) {
# re-executed when inputs (input$bins) change
# 2. Its output type is a plot
output$distPlot <- renderPlot({

x <- faithful$waiting
x <- faithful$waiting
bins <- seq(min(x), max(x), length.out = input$bins + 1)

hist(x, breaks = bins, col = "#75AADB", border = "white",
xlab = "Waiting time to next eruption (in mins)",
main = "Histogram of waiting times")

})

hist(
x,
breaks = bins,
col = "#75AADB",
border = "white",
xlab = "Waiting time to next eruption (in mins)",
main = "Histogram of waiting times"
)
})
}

# Create Shiny app ----
Expand Down
15 changes: 6 additions & 9 deletions inst/examples-shiny/02_text/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ library(bslib)

# Define UI for dataset viewer app ----
ui <- page_sidebar(

# App title ----
title = "Shiny Text",

# Sidebar panel for inputs ----
sidebar = sidebar(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused as to why this newline got removed, but it didn't in 01_hello?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did attempt to add code changes and restore the newlines manually but it was a bit of work so I bailed. So I probably introduced the difference in this line.

# Input: Selector for choosing dataset ----
selectInput(
inputId = "dataset",
Expand All @@ -23,7 +21,6 @@ ui <- page_sidebar(
label = "Number of observations to view:",
value = 10
)

),

# Output: Verbatim text for data summary ----
Expand All @@ -35,13 +32,14 @@ ui <- page_sidebar(

# Define server logic to summarize and view selected dataset ----
server <- function(input, output) {

# Return the requested dataset ----
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars)
switch(
input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars
)
})

# Generate a summary of the dataset ----
Expand All @@ -54,7 +52,6 @@ server <- function(input, output) {
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})

}

# Create Shiny app ----
Expand Down
52 changes: 28 additions & 24 deletions inst/examples-shiny/03_reactivity/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@ library(bslib)

# Define UI for dataset viewer app ----
ui <- page_sidebar(

# App title ----
title = "Reactivity",

# Sidebar panel for inputs ----
sidebar = sidebar(

# Input: Text for providing a caption ----
# Note: Changes made to the caption in the textInput control
# are updated in the output area immediately as you type
textInput(inputId = "caption",
label = "Caption:",
value = "Data Summary"),

# Input: Selector for choosing dataset ----
selectInput(inputId = "dataset",
label = "Choose a dataset:",
choices = c("rock", "pressure", "cars")),

# Input: Numeric entry for number of obs to view ----
numericInput(inputId = "obs",
label = "Number of observations to view:",
value = 10)
# Input: Text for providing a caption ----
# Note: Changes made to the caption in the textInput control
# are updated in the output area immediately as you type
textInput(
inputId = "caption",
label = "Caption:",
value = "Data Summary"
),

# Input: Selector for choosing dataset ----
selectInput(
inputId = "dataset",
label = "Choose a dataset:",
choices = c("rock", "pressure", "cars")
),

# Input: Numeric entry for number of obs to view ----
numericInput(
inputId = "obs",
label = "Number of observations to view:",
value = 10
)
),

# Output: Formatted text for caption ----
Expand All @@ -40,7 +44,6 @@ ui <- page_sidebar(

# Define server logic to summarize and view selected dataset ----
server <- function(input, output) {

# Return the requested dataset ----
# By declaring datasetInput as a reactive expression we ensure
# that:
Expand All @@ -49,10 +52,12 @@ server <- function(input, output) {
# 2. The computation and result are shared by all the callers,
# i.e. it only executes a single time
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars)
switch(
input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars
)
})

# Create caption ----
Expand Down Expand Up @@ -86,7 +91,6 @@ server <- function(input, output) {
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})

}

# Create Shiny app ----
Expand Down
37 changes: 20 additions & 17 deletions inst/examples-shiny/04_mpg/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@ mpgData$am <- factor(mpgData$am, labels = c("Automatic", "Manual"))

# Define UI for miles per gallon app ----
ui <- page_sidebar(

# App title ----
title = "Miles Per Gallon",

# Sidebar panel for inputs ----
sidebar = sidebar(

# Input: Selector for variable to plot against mpg ----
selectInput("variable", "Variable:",
c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear")),

# Input: Checkbox for whether outliers should be included ----
checkboxInput("outliers", "Show outliers", TRUE)

# Input: Selector for variable to plot against mpg ----
selectInput(
"variable",
"Variable:",
c(
"Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear"
)
),

# Input: Checkbox for whether outliers should be included ----
checkboxInput("outliers", "Show outliers", TRUE)
),

# Output: Formatted text for caption ----
Expand All @@ -39,7 +41,6 @@ ui <- page_sidebar(

# Define server logic to plot various variables against mpg ----
server <- function(input, output) {

# Compute the formula text ----
# This is in a reactive expression since it is shared by the
# output$caption and output$mpgPlot functions
Expand All @@ -55,12 +56,14 @@ server <- function(input, output) {
# Generate a plot of the requested variable against mpg ----
# and only exclude outliers if requested
output$mpgPlot <- renderPlot({
boxplot(as.formula(formulaText()),
data = mpgData,
outline = input$outliers,
col = "#75AADB", pch = 19)
boxplot(
as.formula(formulaText()),
data = mpgData,
outline = input$outliers,
col = "#75AADB",
pch = 19
)
})

}

# Create Shiny app ----
Expand Down
116 changes: 69 additions & 47 deletions inst/examples-shiny/05_sliders/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,64 @@ library(bslib)

# Define UI for slider demo app ----
ui <- page_sidebar(

# App title ----
title = "Sliders",

# Sidebar panel for inputs ----
sidebar = sidebar(

# Input: Simple integer interval ----
sliderInput("integer", "Integer:",
min = 0, max = 1000,
value = 500),

# Input: Decimal interval with step value ----
sliderInput("decimal", "Decimal:",
min = 0, max = 1,
value = 0.5, step = 0.1),

# Input: Specification of range within an interval ----
sliderInput("range", "Range:",
min = 1, max = 1000,
value = c(200,500)),

# Input: Custom currency format for with basic animation ----
sliderInput("format", "Custom Format:",
min = 0, max = 10000,
value = 0, step = 2500,
pre = "$", sep = ",",
animate = TRUE),

# Input: Animation with custom interval (in ms) ----
# to control speed, plus looping
sliderInput("animation", "Looping Animation:",
min = 1, max = 2000,
value = 1, step = 10,
animate =
animationOptions(interval = 300, loop = TRUE))

# Input: Simple integer interval ----
sliderInput(
"integer",
"Integer:",
min = 0,
max = 1000,
value = 500
),

# Input: Decimal interval with step value ----
sliderInput(
"decimal",
"Decimal:",
min = 0,
max = 1,
value = 0.5,
step = 0.1
),

# Input: Specification of range within an interval ----
sliderInput(
"range",
"Range:",
min = 1,
max = 1000,
value = c(200, 500)
),

# Input: Custom currency format for with basic animation ----
sliderInput(
"format",
"Custom Format:",
min = 0,
max = 10000,
value = 0,
step = 2500,
pre = "$",
sep = ",",
animate = TRUE
),

# Input: Animation with custom interval (in ms) ----
# to control speed, plus looping
sliderInput(
"animation",
"Looping Animation:",
min = 1,
max = 2000,
value = 1,
step = 10,
animate =
animationOptions(interval = 300, loop = TRUE)
)
),

# Output: Table summarizing the values entered ----
Expand All @@ -48,30 +69,31 @@ ui <- page_sidebar(

# Define server logic for slider examples ----
server <- function(input, output) {

# Reactive expression to create data frame of all input values ----
sliderValues <- reactive({

data.frame(
Name = c("Integer",
"Decimal",
"Range",
"Custom Format",
"Animation"),
Value = as.character(c(input$integer,
input$decimal,
paste(input$range, collapse = " "),
input$format,
input$animation)),
stringsAsFactors = FALSE)

Name = c(
"Integer",
"Decimal",
"Range",
"Custom Format",
"Animation"
),
Value = as.character(c(
input$integer,
input$decimal,
paste(input$range, collapse = " "),
input$format,
input$animation
)),
stringsAsFactors = FALSE
)
})

# Show the values in an HTML table ----
output$values <- renderTable({
sliderValues()
})

}

# Create Shiny app ----
Expand Down
Loading