Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: restyle new examples-shiny apps #4004

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 10 additions & 9 deletions inst/examples-shiny/01_hello/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ ui <- page_sidebar(
max = 50,
value = 30
)

),

# Output: Histogram ----
Expand All @@ -37,16 +36,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
12 changes: 6 additions & 6 deletions inst/examples-shiny/02_text/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ ui <- page_sidebar(
label = "Number of observations to view:",
value = 10
)

),

# Output: Verbatim text for data summary ----
Expand All @@ -38,10 +37,12 @@ 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 +55,6 @@ server <- function(input, output) {
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})

}

# Create Shiny app ----
Expand Down
49 changes: 28 additions & 21 deletions inst/examples-shiny/03_reactivity/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,28 @@ ui <- page_sidebar(
# 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 @@ -49,10 +55,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 +94,6 @@ server <- function(input, output) {
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})

}

# Create Shiny app ----
Expand Down
34 changes: 20 additions & 14 deletions inst/examples-shiny/04_mpg/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ ui <- page_sidebar(
# 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 Down Expand Up @@ -55,12 +59,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
113 changes: 69 additions & 44 deletions inst/examples-shiny/05_sliders/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,59 @@ ui <- page_sidebar(
# 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 @@ -51,27 +74,29 @@ 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
Loading