Skip to content

Commit 44dc082

Browse files
committed
Various additions per recommendations
1 parent a110f42 commit 44dc082

File tree

6 files changed

+89
-18
lines changed

6 files changed

+89
-18
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
.RData
44
.Ruserdata
55

6+
# Ignore cache file
7+
data/cache.Rdata
8+
69
# Mac OS
710
**.DS_Store

README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
## Developing a reproducible Shiny app
22

3-
Shiny application example adopting the recommendations of the "10 Quick Tips for Developing a Reproducible Shiny Application", Brun et al., 2025, PLOS Computational Biology
3+
Example Shiny application adopting the recommendations of "10 Quick Tips for Developing a Reproducible Shiny Application", Brun et al, 2025, PLOS Computational Biology.
44

5-
In this example, we are reusing the Faithful Shiny app example (https://shiny.posit.co/r/gallery/start-simple/faithful/) provided as part of the R ***shiny*** package.
6-
This Shiny application displays eruption data for the Old Faithful geyser.
5+
In this example, we are reusing the Faithful Shiny app example (<https://shiny.posit.co/r/gallery/start-simple/faithful/>) provided as part of the R `shiny` package. This Shiny application displays eruption data for the Old Faithful geyser.
76

8-
## Contributors
7+
Tips demonstrated:
98

10-
## Where to start
9+
- Set up your computing environment
10+
- Use git and GitHub
11+
- Use `renv` to record package versions
12+
- Record the output of `sessionInfo()`
13+
- Document and develop incrementally
14+
- Comment UI elements
15+
- Make your Shiny application portable and easy to maintain
16+
- Organize code and data
17+
- Use relative paths and `file.path`
18+
- Preprocess and cache data for performance
19+
- Cache processed data in a local file
20+
- Make underlying data accessible
21+
- Cite the original data
22+
- License code and data appropriately
23+
- Add a LICENSE file
24+
- Respect the license of the original data
25+
- Make you data and source code citable
26+
- Add README and CITATION.cff files
27+
- Publish your app
28+
- Publish on shinyapps.io and archive in Zenodo
1129

12-
## Acknowledgements
30+
The underlying data is available as part of R package X. The original source is...
1331

32+
Cite this work as: Brun, J., Janée, G., & Curty, R. G. (2025). Example Shiny application adopting the recommendations from "10 Quick Tips for Developing a Reproducible Shiny Application" [Computer software]. <https://github.com/UCSB-Library-Research-Data-Services/shiny-qt-examples>

global.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ library(shiny)
22
library(readr)
33

44
data_path <- "data"
5-
csv_old_faithful <- "faithful_data.csv"
5+
csv_file <- file.path(data_path, "faithful_data.csv")
66

7-
old_faithful <- read_csv(file.path(data_path, csv_old_faithful))
7+
# Below is an example of employing a local cache... not necessary in this case,
8+
# but useful if more processing is involved in preparing the data.
9+
10+
cache_file <- file.path(data_path, "cache.Rdata")
11+
12+
if (file.exists(cache_file) && file.info(cache_file)$mtime > file.info(csv_file)$mtime) {
13+
load(cache_file)
14+
} else {
15+
old_faithful <- read_csv(csv_file)
16+
save(old_faithful, file=cache_file)
17+
}

server.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
function(input, output) {
32

43
output$main_plot <- renderPlot({
@@ -20,4 +19,4 @@ function(input, output) {
2019
}
2120

2221
})
23-
}
22+
}

sessionInfo.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
R version 4.4.1 (2024-06-14)
2+
Platform: aarch64-apple-darwin20
3+
Running under: macOS Monterey 12.7.6
4+
5+
Matrix products: default
6+
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
7+
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
8+
9+
locale:
10+
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
11+
12+
time zone: America/Los_Angeles
13+
tzcode source: internal
14+
15+
attached base packages:
16+
[1] stats graphics grDevices datasets utils methods base
17+
18+
other attached packages:
19+
[1] readr_2.1.5 shiny_1.10.0
20+
21+
loaded via a namespace (and not attached):
22+
[1] crayon_1.5.3 vctrs_0.6.5 cli_3.6.5 rlang_1.1.6
23+
[5] renv_1.1.4 promises_1.3.3 jsonlite_2.0.0 xtable_1.8-4
24+
[9] glue_1.8.0 bit_4.6.0 htmltools_0.5.8.1 httpuv_1.6.16
25+
[13] sass_0.4.10 hms_1.1.3 jquerylib_0.1.4 tibble_3.3.0
26+
[17] tzdb_0.5.0 fastmap_1.2.0 sourcetools_0.1.7-1 lifecycle_1.0.4
27+
[21] memoise_2.0.1 compiler_4.4.1 Rcpp_1.0.14 pkgconfig_2.0.3
28+
[25] later_1.4.2 digest_0.6.37 R6_2.6.1 tidyselect_1.2.1
29+
[29] parallel_4.4.1 vroom_1.6.5 pillar_1.10.2 magrittr_2.0.3
30+
[33] bslib_0.9.0 tools_4.4.1 withr_3.0.2 bit64_4.6.0-1
31+
[37] mime_0.13 cachem_1.1.0

ui.R

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
bootstrapPage(
22

3-
selectInput(inputId = "n_breaks",
3+
selectInput( # bins selector
4+
inputId = "n_breaks",
45
label = "Number of bins in histogram (approximate):",
56
choices = c(10, 20, 35, 50),
6-
selected = 20),
7+
selected = 20
8+
), # end of bins selector
79

8-
checkboxInput(inputId = "individual_obs",
10+
checkboxInput( # individual checkbox
11+
inputId = "individual_obs",
912
label = strong("Show individual observations"),
10-
value = FALSE),
13+
value = FALSE
14+
), # end of individual checkbox
1115

12-
checkboxInput(inputId = "density",
16+
checkboxInput( # density checkbox
17+
inputId = "density",
1318
label = strong("Show density estimate"),
14-
value = FALSE),
19+
value = FALSE
20+
), # end of density checkbox
1521

22+
# main plot area
1623
plotOutput(outputId = "main_plot", height = "300px"),
1724

1825
# Display this only if the density is shown
1926
conditionalPanel(condition = "input.density == true",
20-
sliderInput(inputId = "bw_adjust",
27+
sliderInput( # bandwidth slider
28+
inputId = "bw_adjust",
2129
label = "Bandwidth adjustment:",
22-
min = 0.2, max = 2, value = 1, step = 0.2)
30+
min = 0.2, max = 2, value = 1, step = 0.2
31+
) # end of bandwidth slider
2332
)
2433

2534
)

0 commit comments

Comments
 (0)