Skip to content

Commit ac06350

Browse files
gadenbuiecpsievert
andauthored
chore: restyle new examples-shiny apps (#4004)
* chore: restyle examples-shiny * chore: restore select newlines * More consistent approach to whitespace --------- Co-authored-by: Carson <[email protected]>
1 parent 43698f0 commit ac06350

File tree

11 files changed

+291
-213
lines changed

11 files changed

+291
-213
lines changed

inst/examples-shiny/01_hello/app.R

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ ui <- page_sidebar(
1818
max = 50,
1919
value = 30
2020
)
21-
2221
),
2322

2423
# Output: Histogram ----
@@ -37,16 +36,18 @@ server <- function(input, output) {
3736
# re-executed when inputs (input$bins) change
3837
# 2. Its output type is a plot
3938
output$distPlot <- renderPlot({
40-
41-
x <- faithful$waiting
39+
x <- faithful$waiting
4240
bins <- seq(min(x), max(x), length.out = input$bins + 1)
4341

44-
hist(x, breaks = bins, col = "#75AADB", border = "white",
45-
xlab = "Waiting time to next eruption (in mins)",
46-
main = "Histogram of waiting times")
47-
48-
})
49-
42+
hist(
43+
x,
44+
breaks = bins,
45+
col = "#75AADB",
46+
border = "white",
47+
xlab = "Waiting time to next eruption (in mins)",
48+
main = "Histogram of waiting times"
49+
)
50+
})
5051
}
5152

5253
# Create Shiny app ----

inst/examples-shiny/02_text/app.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ ui <- page_sidebar(
2323
label = "Number of observations to view:",
2424
value = 10
2525
)
26-
2726
),
2827

2928
# Output: Verbatim text for data summary ----
@@ -38,10 +37,12 @@ server <- function(input, output) {
3837

3938
# Return the requested dataset ----
4039
datasetInput <- reactive({
41-
switch(input$dataset,
42-
"rock" = rock,
43-
"pressure" = pressure,
44-
"cars" = cars)
40+
switch(
41+
input$dataset,
42+
"rock" = rock,
43+
"pressure" = pressure,
44+
"cars" = cars
45+
)
4546
})
4647

4748
# Generate a summary of the dataset ----
@@ -54,7 +55,6 @@ server <- function(input, output) {
5455
output$view <- renderTable({
5556
head(datasetInput(), n = input$obs)
5657
})
57-
5858
}
5959

6060
# Create Shiny app ----

inst/examples-shiny/03_reactivity/app.R

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,28 @@ ui <- page_sidebar(
1010
# Sidebar panel for inputs ----
1111
sidebar = sidebar(
1212

13-
# Input: Text for providing a caption ----
14-
# Note: Changes made to the caption in the textInput control
15-
# are updated in the output area immediately as you type
16-
textInput(inputId = "caption",
17-
label = "Caption:",
18-
value = "Data Summary"),
19-
20-
# Input: Selector for choosing dataset ----
21-
selectInput(inputId = "dataset",
22-
label = "Choose a dataset:",
23-
choices = c("rock", "pressure", "cars")),
24-
25-
# Input: Numeric entry for number of obs to view ----
26-
numericInput(inputId = "obs",
27-
label = "Number of observations to view:",
28-
value = 10)
13+
# Input: Text for providing a caption ----
14+
# Note: Changes made to the caption in the textInput control
15+
# are updated in the output area immediately as you type
16+
textInput(
17+
inputId = "caption",
18+
label = "Caption:",
19+
value = "Data Summary"
20+
),
21+
22+
# Input: Selector for choosing dataset ----
23+
selectInput(
24+
inputId = "dataset",
25+
label = "Choose a dataset:",
26+
choices = c("rock", "pressure", "cars")
27+
),
28+
29+
# Input: Numeric entry for number of obs to view ----
30+
numericInput(
31+
inputId = "obs",
32+
label = "Number of observations to view:",
33+
value = 10
34+
)
2935
),
3036

3137
# Output: Formatted text for caption ----
@@ -49,10 +55,12 @@ server <- function(input, output) {
4955
# 2. The computation and result are shared by all the callers,
5056
# i.e. it only executes a single time
5157
datasetInput <- reactive({
52-
switch(input$dataset,
53-
"rock" = rock,
54-
"pressure" = pressure,
55-
"cars" = cars)
58+
switch(
59+
input$dataset,
60+
"rock" = rock,
61+
"pressure" = pressure,
62+
"cars" = cars
63+
)
5664
})
5765

5866
# Create caption ----
@@ -86,7 +94,6 @@ server <- function(input, output) {
8694
output$view <- renderTable({
8795
head(datasetInput(), n = input$obs)
8896
})
89-
9097
}
9198

9299
# Create Shiny app ----

inst/examples-shiny/04_mpg/app.R

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@ ui <- page_sidebar(
1919
# Sidebar panel for inputs ----
2020
sidebar = sidebar(
2121

22-
# Input: Selector for variable to plot against mpg ----
23-
selectInput("variable", "Variable:",
24-
c("Cylinders" = "cyl",
25-
"Transmission" = "am",
26-
"Gears" = "gear")),
27-
28-
# Input: Checkbox for whether outliers should be included ----
29-
checkboxInput("outliers", "Show outliers", TRUE)
30-
22+
# Input: Selector for variable to plot against mpg ----
23+
selectInput(
24+
"variable",
25+
"Variable:",
26+
c(
27+
"Cylinders" = "cyl",
28+
"Transmission" = "am",
29+
"Gears" = "gear"
30+
)
31+
),
32+
33+
# Input: Checkbox for whether outliers should be included ----
34+
checkboxInput("outliers", "Show outliers", TRUE)
3135
),
3236

3337
# Output: Formatted text for caption ----
@@ -55,12 +59,14 @@ server <- function(input, output) {
5559
# Generate a plot of the requested variable against mpg ----
5660
# and only exclude outliers if requested
5761
output$mpgPlot <- renderPlot({
58-
boxplot(as.formula(formulaText()),
59-
data = mpgData,
60-
outline = input$outliers,
61-
col = "#75AADB", pch = 19)
62+
boxplot(
63+
as.formula(formulaText()),
64+
data = mpgData,
65+
outline = input$outliers,
66+
col = "#75AADB",
67+
pch = 19
68+
)
6269
})
63-
6470
}
6571

6672
# Create Shiny app ----

inst/examples-shiny/05_sliders/app.R

Lines changed: 69 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,59 @@ ui <- page_sidebar(
1010
# Sidebar panel for inputs ----
1111
sidebar = sidebar(
1212

13-
# Input: Simple integer interval ----
14-
sliderInput("integer", "Integer:",
15-
min = 0, max = 1000,
16-
value = 500),
17-
18-
# Input: Decimal interval with step value ----
19-
sliderInput("decimal", "Decimal:",
20-
min = 0, max = 1,
21-
value = 0.5, step = 0.1),
22-
23-
# Input: Specification of range within an interval ----
24-
sliderInput("range", "Range:",
25-
min = 1, max = 1000,
26-
value = c(200,500)),
27-
28-
# Input: Custom currency format for with basic animation ----
29-
sliderInput("format", "Custom Format:",
30-
min = 0, max = 10000,
31-
value = 0, step = 2500,
32-
pre = "$", sep = ",",
33-
animate = TRUE),
34-
35-
# Input: Animation with custom interval (in ms) ----
36-
# to control speed, plus looping
37-
sliderInput("animation", "Looping Animation:",
38-
min = 1, max = 2000,
39-
value = 1, step = 10,
40-
animate =
41-
animationOptions(interval = 300, loop = TRUE))
42-
13+
# Input: Simple integer interval ----
14+
sliderInput(
15+
"integer",
16+
"Integer:",
17+
min = 0,
18+
max = 1000,
19+
value = 500
20+
),
21+
22+
# Input: Decimal interval with step value ----
23+
sliderInput(
24+
"decimal",
25+
"Decimal:",
26+
min = 0,
27+
max = 1,
28+
value = 0.5,
29+
step = 0.1
30+
),
31+
32+
# Input: Specification of range within an interval ----
33+
sliderInput(
34+
"range",
35+
"Range:",
36+
min = 1,
37+
max = 1000,
38+
value = c(200, 500)
39+
),
40+
41+
# Input: Custom currency format for with basic animation ----
42+
sliderInput(
43+
"format",
44+
"Custom Format:",
45+
min = 0,
46+
max = 10000,
47+
value = 0,
48+
step = 2500,
49+
pre = "$",
50+
sep = ",",
51+
animate = TRUE
52+
),
53+
54+
# Input: Animation with custom interval (in ms) ----
55+
# to control speed, plus looping
56+
sliderInput(
57+
"animation",
58+
"Looping Animation:",
59+
min = 1,
60+
max = 2000,
61+
value = 1,
62+
step = 10,
63+
animate =
64+
animationOptions(interval = 300, loop = TRUE)
65+
)
4366
),
4467

4568
# Output: Table summarizing the values entered ----
@@ -51,27 +74,29 @@ server <- function(input, output) {
5174

5275
# Reactive expression to create data frame of all input values ----
5376
sliderValues <- reactive({
54-
5577
data.frame(
56-
Name = c("Integer",
57-
"Decimal",
58-
"Range",
59-
"Custom Format",
60-
"Animation"),
61-
Value = as.character(c(input$integer,
62-
input$decimal,
63-
paste(input$range, collapse = " "),
64-
input$format,
65-
input$animation)),
66-
stringsAsFactors = FALSE)
67-
78+
Name = c(
79+
"Integer",
80+
"Decimal",
81+
"Range",
82+
"Custom Format",
83+
"Animation"
84+
),
85+
Value = as.character(c(
86+
input$integer,
87+
input$decimal,
88+
paste(input$range, collapse = " "),
89+
input$format,
90+
input$animation
91+
)),
92+
stringsAsFactors = FALSE
93+
)
6894
})
6995

7096
# Show the values in an HTML table ----
7197
output$values <- renderTable({
7298
sliderValues()
7399
})
74-
75100
}
76101

77102
# Create Shiny app ----

0 commit comments

Comments
 (0)