Skip to content

Commit

Permalink
Added basic template and logic for rendering report (#48)
Browse files Browse the repository at this point in the history
* Added basic template and logic for rendering report

* Moved create report call, added report path creation and copying template

* Updated report with params, yaml error when rendering

* Fixes in the report template

* Fixed bugs

* Fixes in pkg files

* Deleted unused lines

* Fixes for cicd pipeline checks

* Gave user choice for report directory, added messages to report functions, refactored report functions

* Fix 12 create report template (#109)

* file picker added

- rstudioapi dependency added for file picker.
- missing report_dir message added.

* namespace updated

* lint fixes

- lint fix and code styling fix.
- Added lintr default to avoid "no visible global function definition" warning

* dir selection verbose added

* Fix report (#110)

* Removing rstudioapi from the list of dependencies

* adding names to perfomance output list based on the repetition

* Updating benchmark function to work with the new crete_report function

* updating quarto template

* updating and simplifying report auxiliar functions

* Fixing wrong parameter name in create_report call

* running quarto in the destination location (other than root)

* Breaking message into two rows (lintr)

* preventing report to run in case any other problem happens during the benchmark execution

* combining data before sending it to quarto

* adjusting after lintr

* adjusting after lintr

* Making report more robust for different versions

* returning list directly

Co-authored-by: Jakub Nowicki <kuba@appsilon.com>

* using with_dir instead of manually changing working directory

* adding documentation to report utils functions

* updating WORDLIST

---------

Co-authored-by: Jakub Nowicki <kuba@appsilon.com>

* Adding report information to NEWS.md and adding changelog to pkgdown structure

* reorganizing versions in NEWS.md

Co-authored-by: Jakub Nowicki <kuba@appsilon.com>

* adding missing @example tag

---------

Co-authored-by: Maria Drywień <mariadrywien@gmail.com>
Co-authored-by: Douglas R. Mesquita Azevedo <douglasrm.azevedo@gmail.com>
Co-authored-by: Harsh Verma <125121920+insightsurge@users.noreply.github.com>
Co-authored-by: Jakub Nowicki <kuba@appsilon.com>
  • Loading branch information
5 people authored Feb 29, 2024
1 parent c3e3e4b commit 678ef1a
Show file tree
Hide file tree
Showing 20 changed files with 558 additions and 126 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ vignettes/*.pdf
# R Environment Variables
.Renviron

# Rendered reports
performance_report/*

# documentation page
docs
inst/doc
3 changes: 2 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
linters:
linters_with_defaults(
line_length_linter = line_length_linter(100)
line_length_linter = line_length_linter(100),
object_usage_linter = NULL
)
exclusions:
c(
Expand Down
8 changes: 6 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: shiny.benchmark
Title: Benchmark the Performance of Shiny Applications
Version: 0.1.1
Version: 0.1.1.9000
Authors@R:
c(
person(given = "Douglas", family = "Azevedo", email = "opensource+douglas@appsilon.com", role = c("aut", "cre")),
Expand All @@ -20,6 +20,8 @@ Depends:
R (>= 3.1.0)
Suggests:
covr,
DT,
echarts4r,
knitr,
lintr,
rcmdcheck,
Expand All @@ -28,14 +30,16 @@ Suggests:
spelling
Imports:
dplyr,
fs,
ggplot2,
glue,
jsonlite,
methods,
progress,
quarto,
renv,
shinytest2,
stringr,
testthat,
fs
withr
Language: en-US
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ S3method(summary,shiny_benchmark)
export(benchmark)
export(benchmark_cypress)
export(benchmark_shinytest2)
export(combine_performances)
export(create_report)
export(load_example)
export(run_cypress_ptest)
export(run_shinytest2_ptest)
Expand All @@ -17,6 +19,7 @@ importFrom(glue,glue)
importFrom(jsonlite,write_json)
importFrom(methods,new)
importFrom(progress,progress_bar)
importFrom(quarto,quarto_render)
importFrom(renv,activate)
importFrom(renv,restore)
importFrom(shinytest2,test_app)
Expand All @@ -26,3 +29,4 @@ importFrom(testthat,ListReporter)
importFrom(utils,globalVariables)
importFrom(utils,menu)
importFrom(utils,read.table)
importFrom(withr,with_dir)
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.1.1
# shiny.benchmark (development)

Create reports automatically using `report_file` argument in `benchmark` function.

# shiny.benchmark 0.1.1

Adding a minimal example using `shinytest2`
37 changes: 27 additions & 10 deletions R/benchmark.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@
#' @param renv_prompt Prompt the user before taking any action?
#' @param n_rep Number of replications desired
#' @param debug Logical. TRUE to display all the system messages on runtime
#' @param report_file Name of the file (.html) where the report should be saved,
#' when default (NULL), then report is not saved
#'
#' @importFrom glue glue
#' @export
benchmark <- function(
commit_list,
cypress_dir = NULL,
shinytest2_dir = NULL,
tests_pattern = NULL,
app_dir = getwd(),
port = 3333,
use_renv = TRUE,
renv_prompt = TRUE,
n_rep = 1,
debug = FALSE
commit_list,
cypress_dir = NULL,
shinytest2_dir = NULL,
tests_pattern = NULL,
app_dir = getwd(),
port = 3333,
use_renv = TRUE,
renv_prompt = TRUE,
n_rep = 1,
debug = FALSE,
report_file = NULL
) {
# Get the call parameters
call_benchmark <- match.call()
Expand Down Expand Up @@ -102,5 +105,19 @@ benchmark <- function(
)
class(out) <- "shiny_benchmark"

# create report conditionally
if (!is.null(report_file)) {
# combine performances into a single data.frame
performance <- combine_performances(
performance <- out$performance
)

# create report
create_report(
report_params = list(performance = performance),
file = report_file
)
}

return(out)
}
35 changes: 18 additions & 17 deletions R/benchmark_cypress.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
#'
#' @export
benchmark_cypress <- function(
commit_list,
cypress_dir,
tests_pattern,
app_dir,
port,
use_renv,
renv_prompt,
n_rep,
debug
commit_list,
cypress_dir,
tests_pattern,
app_dir,
port,
use_renv,
renv_prompt,
n_rep,
debug
) {
# creating the structure
project_path <- create_cypress_structure(
Expand Down Expand Up @@ -93,14 +93,14 @@ benchmark_cypress <- function(
#' @importFrom utils read.table
#' @export
run_cypress_ptest <- function(
commit,
project_path,
cypress_dir,
tests_pattern,
use_renv,
renv_prompt,
n_rep,
debug
commit,
project_path,
cypress_dir,
tests_pattern,
use_renv,
renv_prompt,
n_rep,
debug
) {
# checkout to the desired commit
checkout(branch = commit, debug = debug)
Expand Down Expand Up @@ -144,5 +144,6 @@ run_cypress_ptest <- function(
checkout_files(debug = debug)

# return times
names(perf_file) <- paste0("rep", 1:n_rep)
return(perf_file)
}
35 changes: 18 additions & 17 deletions R/benchmark_shinytest2.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
#'
#' @export
benchmark_shinytest2 <- function(
commit_list,
shinytest2_dir,
tests_pattern,
app_dir,
use_renv,
renv_prompt,
n_rep,
debug
commit_list,
shinytest2_dir,
tests_pattern,
app_dir,
use_renv,
renv_prompt,
n_rep,
debug
) {

# creating the structure
Expand Down Expand Up @@ -91,15 +91,15 @@ benchmark_shinytest2 <- function(
#' @importFrom shinytest2 test_app
#' @export
run_shinytest2_ptest <- function(
commit,
project_path,
app_dir,
shinytest2_dir,
tests_pattern,
use_renv,
renv_prompt,
n_rep,
debug
commit,
project_path,
app_dir,
shinytest2_dir,
tests_pattern,
use_renv,
renv_prompt,
n_rep,
debug
) {
# checkout to the desired commit
checkout(branch = commit, debug = debug)
Expand Down Expand Up @@ -145,5 +145,6 @@ run_shinytest2_ptest <- function(
checkout_files(debug = debug)

# return times
names(perf_file) <- paste0("rep", 1:n_rep)
return(perf_file)
}
1 change: 0 additions & 1 deletion R/shiny_benchmark-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#' @importFrom methods new
#'
#' @export

shiny_benchmark_class <- setClass(
Class = "shiny_benchmark",
representation(
Expand Down
51 changes: 23 additions & 28 deletions R/utils_cypress.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,29 @@ create_cypress_structure <- function(app_dir, port, debug) {
fs::dir_create(path = plugins_path)

# create a path root linked to the main directory app
tryCatch(
expr = {
fs::link_create(app_dir, root_path, symbolic = TRUE)
},
error = function(e) {

choice <- menu(
choices = c("Yes", "No"),
title = glue(
"A symbolic link cannot be created, it is possible to clone ",
"the repository, but it can take some time and space on disk. ",
"Would you like to proceed with this operations?")
)

if (choice == 2)
stop("Process aborted by user.")

# If system cannot symlink then try to clone the repository
# This may happen on some windows versions
# This can be an expensive operation on big repositories
message(
"Could not create symbolic link with fs package, ",
"trying with git clone..."
)
system(glue::glue("git clone \"{app_dir}\" \"{root_path}\""))
system("git submodule init")
system("git submodule update ")
})
tryCatch(expr = {
fs::link_create(app_dir, root_path, symbolic = TRUE)
},
error = function(e) {
choice <- menu(
choices = c("Yes", "No"),
title = glue("A symbolic link cannot be created, it is possible to clone ",
"the repository, but it can take some time and space on disk. ",
"Would you like to proceed with this operations?")
)
if (choice == 2)
stop("Process aborted by user.")
# If system cannot symlink then try to clone the repository
# This may happen on some windows versions
# This can be an expensive operation on big repositories
message(
"Could not create symbolic link with fs package, ",
"trying with git clone..."
)
system(glue::glue("git clone \"{app_dir}\" \"{root_path}\""))
system("git submodule init")
system("git submodule update ")
})

# create the packages.json file
json_txt <- create_node_list(tests_path = tests_path, port = port)
Expand Down
Loading

0 comments on commit 678ef1a

Please sign in to comment.