Skip to content

Commit 4c22b13

Browse files
committed
chore: restyle examples-shiny
1 parent 47fb562 commit 4c22b13

File tree

11 files changed

+291
-239
lines changed

11 files changed

+291
-239
lines changed

inst/shiny/01_hello/app.R

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ library(bslib)
33

44
# Define UI for app that draws a histogram ----
55
ui <- page_sidebar(
6-
76
# App title ----
87
title = "Hello Shiny!",
98

@@ -18,7 +17,6 @@ ui <- page_sidebar(
1817
max = 50,
1918
value = 30
2019
)
21-
2220
),
2321

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

2826
# Define server logic required to draw a histogram ----
2927
server <- function(input, output) {
30-
3128
# Histogram of the Old Faithful Geyser Data ----
3229
# with requested number of bins
3330
# This expression that generates a histogram is wrapped in a call
@@ -37,16 +34,18 @@ server <- function(input, output) {
3734
# re-executed when inputs (input$bins) change
3835
# 2. Its output type is a plot
3936
output$distPlot <- renderPlot({
40-
41-
x <- faithful$waiting
37+
x <- faithful$waiting
4238
bins <- seq(min(x), max(x), length.out = input$bins + 1)
4339

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-
40+
hist(
41+
x,
42+
breaks = bins,
43+
col = "#75AADB",
44+
border = "white",
45+
xlab = "Waiting time to next eruption (in mins)",
46+
main = "Histogram of waiting times"
47+
)
48+
})
5049
}
5150

5251
# Create Shiny app ----

inst/shiny/02_text/app.R

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ library(bslib)
33

44
# Define UI for dataset viewer app ----
55
ui <- page_sidebar(
6-
76
# App title ----
87
title = "Shiny Text",
98

109
# Sidebar panel for inputs ----
1110
sidebar = sidebar(
12-
1311
# Input: Selector for choosing dataset ----
1412
selectInput(
1513
inputId = "dataset",
@@ -23,7 +21,6 @@ ui <- page_sidebar(
2321
label = "Number of observations to view:",
2422
value = 10
2523
)
26-
2724
),
2825

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

3633
# Define server logic to summarize and view selected dataset ----
3734
server <- function(input, output) {
38-
3935
# Return the requested dataset ----
4036
datasetInput <- reactive({
41-
switch(input$dataset,
42-
"rock" = rock,
43-
"pressure" = pressure,
44-
"cars" = cars)
37+
switch(
38+
input$dataset,
39+
"rock" = rock,
40+
"pressure" = pressure,
41+
"cars" = cars
42+
)
4543
})
4644

4745
# Generate a summary of the dataset ----
@@ -54,7 +52,6 @@ server <- function(input, output) {
5452
output$view <- renderTable({
5553
head(datasetInput(), n = input$obs)
5654
})
57-
5855
}
5956

6057
# Create Shiny app ----

inst/shiny/03_reactivity/app.R

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,33 @@ library(bslib)
33

44
# Define UI for dataset viewer app ----
55
ui <- page_sidebar(
6-
76
# App title ----
87
title = "Reactivity",
98

109
# Sidebar panel for inputs ----
1110
sidebar = sidebar(
12-
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)
11+
# Input: Text for providing a caption ----
12+
# Note: Changes made to the caption in the textInput control
13+
# are updated in the output area immediately as you type
14+
textInput(
15+
inputId = "caption",
16+
label = "Caption:",
17+
value = "Data Summary"
18+
),
19+
20+
# Input: Selector for choosing dataset ----
21+
selectInput(
22+
inputId = "dataset",
23+
label = "Choose a dataset:",
24+
choices = c("rock", "pressure", "cars")
25+
),
26+
27+
# Input: Numeric entry for number of obs to view ----
28+
numericInput(
29+
inputId = "obs",
30+
label = "Number of observations to view:",
31+
value = 10
32+
)
2933
),
3034

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

4145
# Define server logic to summarize and view selected dataset ----
4246
server <- function(input, output) {
43-
4447
# Return the requested dataset ----
4548
# By declaring datasetInput as a reactive expression we ensure
4649
# that:
@@ -49,10 +52,12 @@ server <- function(input, output) {
4952
# 2. The computation and result are shared by all the callers,
5053
# i.e. it only executes a single time
5154
datasetInput <- reactive({
52-
switch(input$dataset,
53-
"rock" = rock,
54-
"pressure" = pressure,
55-
"cars" = cars)
55+
switch(
56+
input$dataset,
57+
"rock" = rock,
58+
"pressure" = pressure,
59+
"cars" = cars
60+
)
5661
})
5762

5863
# Create caption ----
@@ -86,7 +91,6 @@ server <- function(input, output) {
8691
output$view <- renderTable({
8792
head(datasetInput(), n = input$obs)
8893
})
89-
9094
}
9195

9296
# Create Shiny app ----

inst/shiny/04_mpg/app.R

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@ mpgData$am <- factor(mpgData$am, labels = c("Automatic", "Manual"))
1212

1313
# Define UI for miles per gallon app ----
1414
ui <- page_sidebar(
15-
1615
# App title ----
1716
title = "Miles Per Gallon",
1817

1918
# Sidebar panel for inputs ----
2019
sidebar = sidebar(
21-
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-
20+
# Input: Selector for variable to plot against mpg ----
21+
selectInput(
22+
"variable",
23+
"Variable:",
24+
c(
25+
"Cylinders" = "cyl",
26+
"Transmission" = "am",
27+
"Gears" = "gear"
28+
)
29+
),
30+
31+
# Input: Checkbox for whether outliers should be included ----
32+
checkboxInput("outliers", "Show outliers", TRUE)
3133
),
3234

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

4042
# Define server logic to plot various variables against mpg ----
4143
server <- function(input, output) {
42-
4344
# Compute the formula text ----
4445
# This is in a reactive expression since it is shared by the
4546
# output$caption and output$mpgPlot functions
@@ -55,12 +56,14 @@ server <- function(input, output) {
5556
# Generate a plot of the requested variable against mpg ----
5657
# and only exclude outliers if requested
5758
output$mpgPlot <- renderPlot({
58-
boxplot(as.formula(formulaText()),
59-
data = mpgData,
60-
outline = input$outliers,
61-
col = "#75AADB", pch = 19)
59+
boxplot(
60+
as.formula(formulaText()),
61+
data = mpgData,
62+
outline = input$outliers,
63+
col = "#75AADB",
64+
pch = 19
65+
)
6266
})
63-
6467
}
6568

6669
# Create Shiny app ----

inst/shiny/05_sliders/app.R

Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,64 @@ library(bslib)
33

44
# Define UI for slider demo app ----
55
ui <- page_sidebar(
6-
76
# App title ----
87
title = "Sliders",
98

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

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

4970
# Define server logic for slider examples ----
5071
server <- function(input, output) {
51-
5272
# Reactive expression to create data frame of all input values ----
5373
sliderValues <- reactive({
54-
5574
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-
75+
Name = c(
76+
"Integer",
77+
"Decimal",
78+
"Range",
79+
"Custom Format",
80+
"Animation"
81+
),
82+
Value = as.character(c(
83+
input$integer,
84+
input$decimal,
85+
paste(input$range, collapse = " "),
86+
input$format,
87+
input$animation
88+
)),
89+
stringsAsFactors = FALSE
90+
)
6891
})
6992

7093
# Show the values in an HTML table ----
7194
output$values <- renderTable({
7295
sliderValues()
7396
})
74-
7597
}
7698

7799
# Create Shiny app ----

0 commit comments

Comments
 (0)