| /R/run_app.R | Memory | Time | ||||||
|---|---|---|---|---|---|---|---|---|
| #' Run example app | ||||||||
| #' | ||||||||
| #' @return A shiny app object | ||||||||
| #' @export | ||||||||
| #' @import shiny | ||||||||
| run_app_audit <- function() { # nocov start | ||||||||
| # serve js tools for Monkey test (in case proxy blocks external scripts) | ||||||||
| addResourcePath("gremlins", system.file("shinyValidator-js", package = "shinyValidator")) | ||||||||
| # DON'T CHANGE (INTERNAL TO SHINYVALIDATOR) | ||||||||
| p <- parent.frame(1) | ||||||||
| .enable_reactlog <- p[[".enable_reactlog"]] | ||||||||
| .profile_code <- p[[".profile_code"]] | ||||||||
| if (is.null(.enable_reactlog)) .enable_reactlog <- FALSE | ||||||||
| if (is.null(.profile_code)) .profile_code <- FALSE | ||||||||
| if (.enable_reactlog || .profile_code) { | ||||||||
| tmp <- body(app_server) | ||||||||
| start <- length(tmp) + 1 # start just before the closing } | ||||||||
| body(app_server)[[start]] <- substitute( | ||||||||
| onSessionEnded(function() { | ||||||||
| message("CI/CD callback: APP successfully stopped by chrome") | ||||||||
| stopApp(reactlog()) | ||||||||
| }) | ||||||||
| ) | ||||||||
| } | ||||||||
| runApp( | ||||||||
| shinyApp(app_ui, app_server), | ||||||||
| test.mode = TRUE | ||||||||
| ) | ||||||||
| } # nocov end | ||||||||
| globalVariables(c("app_ui", "app_server")) | ||||||||
| /R/app_ui.R | Memory | Time | ||||||
|---|---|---|---|---|---|---|---|---|
| app_ui <- function() { # nocov start | ||||||||
| fluidPage( | ||||||||
| sliderInput( | ||||||||
| "obs", | ||||||||
| "Number of observations:", | ||||||||
| min = 0, | ||||||||
| max = 1000, | ||||||||
| value = 500 | ||||||||
| ), | ||||||||
| plotOutput("distPlot") | ||||||||
| ) | ||||||||
| } # nocov end | ||||||||
| /R/app_server.R | Memory | Time | ||||||
|---|---|---|---|---|---|---|---|---|
| app_server <- function(input, output, session) { # nocov start | ||||||||
| output$distPlot <- renderPlot({ | ||||||||
| slow_func(5*10^4) | ||||||||
| graphics::hist(stats::rnorm(input$obs)) | ||||||||
| }) | ||||||||
| } # nocov end | ||||||||
| /R/utils.R | Memory | Time | ||||||
|---|---|---|---|---|---|---|---|---|
| on_ci <- function() { | ||||||||
| isTRUE(as.logical(Sys.getenv("CI"))) | ||||||||
| } | ||||||||
| # Useful for testing code profile on laggy code | ||||||||
| slow_func <- function(n) { | ||||||||
| vec <- NULL # Or vec = c() | ||||||||
| for (i in seq_len(n)) | ||||||||
| vec <- c(vec, i) | ||||||||
| vec | ||||||||
| } | ||||||||