diff --git a/.Rbuildignore b/.Rbuildignore index d5e53830d..4ba875e70 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -25,3 +25,5 @@ _\.new\.png$ ^source$ ^revdep ^revdep$ +^manifest.json$ +^\.rscignore$ diff --git a/DESCRIPTION b/DESCRIPTION index 82f24bc7c..53831c172 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: riskassessment Title: A web app designed to interface with the `riskmetric` package -Version: 3.0.0.9014 +Version: 3.0.0.9015 Authors@R: c( person("Aaron", "Clark", role = c("aut", "cre"), email = "aaron.clark@biogen.com"), person("Robert", "Krajcik", role = "aut", email = "robert.krajcik@biogen.com"), @@ -41,6 +41,7 @@ Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 Imports: bslib (>= 0.3.0), + callr, config (>= 0.3.1), cranlogs, DBI, diff --git a/NAMESPACE b/NAMESPACE index 8bbcf33e8..45987ea1b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -28,6 +28,7 @@ importFrom(RSQLite,sqliteCopyDatabase) importFrom(archive,archive) importFrom(archive,archive_read) importFrom(bslib,bs_theme) +importFrom(callr,r_bg) importFrom(cranlogs,cran_downloads) importFrom(desc,desc_fields) importFrom(desc,desc_get_field) diff --git a/NEWS.md b/NEWS.md index bb4ce4c8c..7ff280c89 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,7 @@ * Shorten waiting time in code explorer/package explorer by reading tarballs in memory (#707) * Move package upload process to a function * Updated logo in reports to lighter version to match application UI +* Run report building in background if several are being requested (#711) # riskassessment 3.0.0 diff --git a/R/global.R b/R/global.R index dc673cdb3..cffa1c1bc 100644 --- a/R/global.R +++ b/R/global.R @@ -42,6 +42,7 @@ utils::globalVariables( 'downloads', 'ea_v', 'estimate', + 'explore_metrics', 'func', 'have_changed', 'Last modified', @@ -69,6 +70,7 @@ utils::globalVariables( 'rpt_choices', 'score', 'setNames', + 'status', 'succ_icon', 'text', 'token', diff --git a/R/mod_downloadHandler.R b/R/mod_downloadHandler.R index 573d8af69..c64efcf36 100644 --- a/R/mod_downloadHandler.R +++ b/R/mod_downloadHandler.R @@ -8,7 +8,7 @@ mod_downloadHandler_button_ui <- function(id, multiple = TRUE){ ns <- NS(id) tagList( - downloadButton(ns("download_reports"), if (multiple) "Download Report(s)" else "Download Report") + actionButton(ns("create_reports"), if (multiple) "Create Report(s)" else "Create Report") ) } @@ -102,23 +102,35 @@ mod_downloadHandler_include_server <- function(id) { #' #' @importFrom flextable flextable set_table_properties colformat_char #' -#' @noRd +#' @noRd +#' @importFrom callr r_bg mod_downloadHandler_server <- function(id, pkgs, user, metric_weights){ moduleServer( id, function(input, output, session){ ns <- session$ns observe({ if(isTruthy(pkgs())) { - shinyjs::enable("download_reports") + shinyjs::enable("create_reports") } else { - shinyjs::disable("download_reports") + shinyjs::disable("create_reports") } }) + download_file <- reactiveValues() - output$download_reports <- downloadHandler( - filename = function() { - n_pkgs <- length(pkgs()) - + observeEvent(input$create_reports, { + + n_pkgs <- length(pkgs()) + req(n_pkgs > 0) + + if (!isTruthy(session$userData$repo_pkgs())) { + if (isTRUE(getOption("shiny.testmode"))) { + session$userData$repo_pkgs(purrr::map_dfr(test_pkg_refs, ~ as.data.frame(.x, col.names = c("Package", "Version", "Source")))) + } else { + session$userData$repo_pkgs(as.data.frame(utils::available.packages()[,1:2])) + } + } + + download_file$filename <- { if (n_pkgs > 1) { report_datetime <- stringr::str_replace_all(stringr::str_replace(get_time(), " ", "_"), ":", "-") glue::glue('RiskAssessment-Report-{report_datetime}.zip') @@ -126,201 +138,103 @@ mod_downloadHandler_server <- function(id, pkgs, user, metric_weights){ pkg_ver <- dbSelect("SELECT version FROM package WHERE name = {pkgs()}") glue::glue('{pkgs()}_{pkg_ver}_Risk_Assessment.{input$report_format}') } - }, - content = function(file) { - n_pkgs <- length(pkgs()) + } + + if (n_pkgs < 4) { + progress <- shiny::Progress$new(max = n_pkgs + 1) + progress$set(message = glue::glue('Downloading {ifelse(n_pkgs > 1, paste0(n_pkgs, " "), "")}Report{ifelse(n_pkgs > 1, "s:", ":")}'), + detail = if(n_pkgs == 1) pkgs(), + value = 0) + on.exit(progress$close()) - req(n_pkgs > 0) + updateProgress <- function(amount = 1, detail = NULL) { + progress$inc(amount = amount, detail = detail) + } + + download_file$filepath <- + report_creation(pkgs(), metric_weights(), input$report_format, input$report_includes, reactiveValuesToList(user), session$userData$loaded2_db(), session$userData$repo_pkgs(), updateProgress = updateProgress) + } else { + download_file$progress <- shiny::Progress$new(max = n_pkgs + 2) + download_file$progress$set(message = glue::glue('Downloading {ifelse(n_pkgs > 1, paste0(n_pkgs, " "), "")}Report{ifelse(n_pkgs > 1, "s:", ":")}'), + detail = "Setting up background process", + value = 1) - if (!isTruthy(session$userData$repo_pkgs())) { - if (isTRUE(getOption("shiny.testmode"))) { - session$userData$repo_pkgs(purrr::map_dfr(test_pkg_refs, ~ as.data.frame(.x, col.names = c("Package", "Version", "Source")))) - } else { - session$userData$repo_pkgs(as.data.frame(utils::available.packages()[,1:2])) - } + updateProgress <- function(amount = 1, detail = NULL) { + cat("", amount, ":", detail, "", "\n", sep = "") } - shiny::withProgress( - message = glue::glue('Downloading {ifelse(n_pkgs > 1, paste0(n_pkgs, " "), "")}Report{ifelse(n_pkgs > 1, "s", paste0(": ", pkgs()))}'), - value = 0, - max = n_pkgs + 2, # Tell the progress bar the total number of events. - { - shiny::incProgress(1) - - my_tempdir <- tempdir() - if (input$report_format == "html") { - - # https://github.com/rstudio/fontawesome/issues/99 - # Here, we make sure user has a functional version of fontawesome - fa_v <- packageVersion("fontawesome") - if(fa_v == '0.4.0') { - msg1 <- "HTML reports will not render with {fontawesome} v0.4.0." - msg2 <- glue::glue("You currently have v{fa_v} installed. If the report download failed, please install a stable version. We recommend v0.5.0 or higher.") - warning(paste(msg1, msg2)) - showModal(modalDialog( - size = "l", - title = h3(msg1, class = "mb-0 mt-0 txt-color"), - h5(msg2) - )) - } - - Report <- file.path(my_tempdir, "reportHtml.Rmd") - file.copy(app_sys('report_downloads', 'reportHtml.Rmd'), Report, overwrite = TRUE) - file.copy(app_sys('report_downloads', 'raa-image.png'), - file.path(my_tempdir, 'raa-image.png'), overwrite = TRUE) - file.copy(app_sys('report_downloads', 'header.html'), - file.path(my_tempdir, 'header.html'), overwrite = TRUE) - } - else if (input$report_format == "docx") { - Report <- file.path(my_tempdir, "reportDocx.Rmd") - if (!dir.exists(file.path(my_tempdir, "images"))) - dir.create(file.path(my_tempdir, "images")) - file.copy(app_sys('report_downloads', 'reportDocx.Rmd'), - Report, - overwrite = TRUE) - file.copy(app_sys('report_downloads', 'header.docx'), - file.path(my_tempdir, 'header.docx'), - overwrite = TRUE) - file.copy(app_sys('report_downloads', 'read_html.lua'), - file.path(my_tempdir, "read_html.lua"), overwrite = TRUE) - file.copy(app_sys('report_downloads', 'images', 'user-tie.png'), - file.path(my_tempdir, "images", "user-tie.png"), - overwrite = TRUE) - file.copy(app_sys('report_downloads', 'images', 'user-shield.png'), - file.path(my_tempdir, "images", "user-shield.png"), - overwrite = TRUE) - file.copy(app_sys('report_downloads', 'images', 'calendar-alt.png'), - file.path(my_tempdir, "images", "calendar-alt.png"), - overwrite = TRUE) - file.copy(app_sys('report_downloads', 'raa-image.png'), - file.path(my_tempdir, 'raa-image.png'), overwrite = TRUE) - } - else { - Report <- file.path(my_tempdir, "reportPdf.Rmd") - if (!dir.exists(file.path(my_tempdir, "images"))) - dir.create(file.path(my_tempdir, "images")) - file.copy(app_sys('report_downloads', 'reportPdf.Rmd'), - Report, - overwrite = TRUE) - file.copy(app_sys('report_downloads', 'header.tex'), - file.path(my_tempdir, 'header.tex'), - overwrite = TRUE) - file.copy(app_sys('report_downloads', 'fancyhdr.sty'), - file.path(my_tempdir, 'fancyhdr.sty'), - overwrite = TRUE) - file.copy(app_sys('report_downloads', 'read_html.lua'), - file.path(my_tempdir, "read_html.lua"), overwrite = TRUE) - file.copy(app_sys('report_downloads', 'images', 'user-tie.png'), - file.path(my_tempdir, "images", "user-tie.png"), - overwrite = TRUE) - file.copy(app_sys('report_downloads', 'images', 'user-shield.png'), - file.path(my_tempdir, "images", "user-shield.png"), - overwrite = TRUE) - file.copy(app_sys('report_downloads', 'images', 'calendar-alt.png'), - file.path(my_tempdir, "images", "calendar-alt.png"), - overwrite = TRUE) - file.copy(app_sys('report_downloads', 'raa-image.png'), - file.path(my_tempdir, 'raa-image.png'), overwrite = TRUE) - } - - fs <- c() - for (i in 1:n_pkgs) { - # Grab package name and version, then create filename and path. - # this_pkg <- "stringr" # for testing - selected_pkg <- get_pkg_info(pkgs()[i]) - this_pkg <- selected_pkg$name - this_ver <- selected_pkg$version - file_named <- glue::glue('{this_pkg}_{this_ver}_Risk_Assessment.{input$report_format}') - path <- if (n_pkgs > 1) { - file.path(my_tempdir, file_named) - } else { - file - } - - pkg_list <- list( - id = selected_pkg$id, - name = selected_pkg$name, - version = selected_pkg$version, - date_added = selected_pkg$date_added, - title = selected_pkg$title, - decision = selected_pkg$decision, - description = selected_pkg$description, - author = selected_pkg$author, - maintainer = selected_pkg$maintainer, - license = selected_pkg$license, - published = selected_pkg$published_on, - score = selected_pkg$score - ) - - # gather comments data - overall_comments <- get_overall_comments(this_pkg) - pkg_summary <- get_pkg_summary(this_pkg) - mm_comments <- get_mm_comments(this_pkg) - cm_comments <- get_cm_comments(this_pkg) - se_comments <- get_se_comments(this_pkg) - fe_comments <- get_fe_comments(this_pkg) - - # gather maint metrics & community metric data - mm_data <- get_metric_data(this_pkg, metric_class = "maintenance") - comm_data <- get_comm_data(this_pkg) - comm_cards <- build_comm_cards(comm_data) - downloads_plot <- build_comm_plotly(comm_data) - metric_tbl <- dbSelect("select * from metric", db_name = golem::get_golem_options('assessment_db_name')) - - dep_metrics <- get_depends_data(this_pkg, db_name = golem::get_golem_options("assessment_db_name")) - - dep_cards <- build_dep_cards(data = dep_metrics, loaded = session$userData$loaded2_db()$name, toggled = 0L) - - dep_table <- - if (nrow(dep_metrics) == 0) { - dplyr::tibble(package = character(), type = character(), version = character(), score = character()) - } else { - purrr::map_df(dep_metrics$name, ~get_versnScore(.x, session$userData$loaded2_db(), session$userData$repo_pkgs())) %>% - right_join(dep_metrics, by = "name") %>% - select(package, type, version, score) %>% - arrange(package, type) %>% - distinct() - } - - # Render the report, passing parameters to the rmd file. - rmarkdown::render( - input = Report, - output_file = path, - clean = FALSE, - params = list(pkg = pkg_list, - report_includes = input$report_includes, - riskmetric_version = paste0(packageVersion("riskmetric")), - app_version = golem::get_golem_options('app_version'), - metric_weights = metric_weights(), - user_name = user$name, - user_role = paste(user$role, collapse = ', '), - overall_comments = overall_comments, - pkg_summary = pkg_summary, - mm_comments = mm_comments, - cm_comments = cm_comments, - se_comments = se_comments, - fe_comments = fe_comments, - maint_metrics = mm_data, - com_metrics = comm_cards, - com_metrics_raw = comm_data, - downloads_plot_data = downloads_plot, - dep_cards = dep_cards, - dep_table = dep_table, - metric_tbl = metric_tbl - ) - ) - fs <- c(fs, path) # Save all the reports/ - shiny::incProgress(1) # Increment progress bar. - } - # Zip all the files up. -j retains just the files in zip file. - if (n_pkgs > 1) zip(zipfile = file, files = fs, extras = "-j") - shiny::incProgress(1) # Increment progress bar. - }) + shinyjs::disable("create_reports") + download_file$background <- + callr::r_bg( + function(...) { + pkgload::load_all(export_all = TRUE, helpers = FALSE, attach_testthat = FALSE) + report_creation(...) + }, + list(pkg_lst = pkgs(), metric_weights = metric_weights(), + report_format = input$report_format, report_includes = input$report_includes, + user = reactiveValuesToList(user), + loaded2_db = session$userData$loaded2_db(), repo_pkgs = session$userData$repo_pkgs(), + db_name = golem::get_golem_options('assessment_db_name'), my_tempdir = tempdir(), + updateProgress = updateProgress), + user_profile = FALSE + ) + } + }) + + observe({ + req(download_file$background) + + out <- + download_file$background$read_output_lines() %>% + `[`(grepl(pattern = "^.*?$", .)) + if (length(out) > 0) { + out <- + sub("", "", out) %>% + sub(pattern = "", replacement = "") %>% + strsplit(":") + purrr::walk(out, ~ { + download_file$progress$inc(amount = as.numeric(.x[1]), detail = if (!is.na(.x[2])) .x[2]) + }) + } + if (download_file$background$is_alive()) { + invalidateLater(1000, session) + } else { + download_file$progress$close() + download_file$filepath <- download_file$background$get_result() + shinyjs::enable("create_reports") + } + }) + + observeEvent(download_file$filepath, { + showNotification("Reports created", + action = downloadLink(ns("download_reports")), + id = ns("dr_id"), + duration = NULL) + }) + + output$download_reports <- downloadHandler( + filename = function() { + if (length(download_file$filepath) > 1) { + report_datetime <- stringr::str_replace_all(stringr::str_replace(get_time(), " ", "_"), ":", "-") + glue::glue('RiskAssessment-Report-{report_datetime}.zip') + } else { + basename(download_file$filename) + } + }, + content = function(file) { + removeNotification(ns("dr_id")) + + if (length(download_file$filepath) > 1) { + zip(zipfile = file, files = download_file$filepath, extras = "-j") + } else { + file.copy(from = download_file$filepath, to = file) + } + download_file$filepath <- NULL } ) }) } - + ## To be copied in the UI # mod_downloadHandler_button_ui("downloadHandler_1") diff --git a/R/mod_downloadHandler_utils.R b/R/mod_downloadHandler_utils.R new file mode 100644 index 000000000..5c196c95c --- /dev/null +++ b/R/mod_downloadHandler_utils.R @@ -0,0 +1,181 @@ +#' asynch +#' +#' @description A utils function +#' +#' @return The return value, if any, from executing the utility. +#' +#' @noRd +report_creation <- function(pkg_lst, metric_weights, report_format, report_includes, user, + loaded2_db, repo_pkgs, + db_name = golem::get_golem_options('assessment_db_name'), + my_tempdir = tempdir(), updateProgress = NULL) { + n_pkgs <- length(pkg_lst) + + if (report_format == "html") { + + # https://github.com/rstudio/fontawesome/issues/99 + # Here, we make sure user has a functional version of fontawesome + fa_v <- packageVersion("fontawesome") + if(fa_v == '0.4.0') { + msg1 <- "HTML reports will not render with {fontawesome} v0.4.0." + msg2 <- glue::glue("You currently have v{fa_v} installed. If the report download failed, please install a stable version. We recommend v0.5.0 or higher.") + warning(paste(msg1, msg2)) + showModal(modalDialog( + size = "l", + title = h3(msg1, class = "mb-0 mt-0 txt-color"), + h5(msg2) + )) + } + + Report <- file.path(my_tempdir, "reportHtml.Rmd") + file.copy(app_sys('report_downloads', 'reportHtml.Rmd'), Report, overwrite = TRUE) + file.copy(app_sys('report_downloads', 'raa-image.png'), + file.path(my_tempdir, 'raa-image.png'), overwrite = TRUE) + file.copy(app_sys('report_downloads', 'header.html'), + file.path(my_tempdir, 'header.html'), overwrite = TRUE) + } + else if (report_format == "docx") { + Report <- file.path(my_tempdir, "reportDocx.Rmd") + if (!dir.exists(file.path(my_tempdir, "images"))) + dir.create(file.path(my_tempdir, "images")) + file.copy(app_sys('report_downloads', 'reportDocx.Rmd'), + Report, + overwrite = TRUE) + file.copy(app_sys('report_downloads', 'header.docx'), + file.path(my_tempdir, 'header.docx'), + overwrite = TRUE) + file.copy(app_sys('report_downloads', 'read_html.lua'), + file.path(my_tempdir, "read_html.lua"), overwrite = TRUE) + file.copy(app_sys('report_downloads', 'images', 'user-tie.png'), + file.path(my_tempdir, "images", "user-tie.png"), + overwrite = TRUE) + file.copy(app_sys('report_downloads', 'images', 'user-shield.png'), + file.path(my_tempdir, "images", "user-shield.png"), + overwrite = TRUE) + file.copy(app_sys('report_downloads', 'images', 'calendar-alt.png'), + file.path(my_tempdir, "images", "calendar-alt.png"), + overwrite = TRUE) + file.copy(app_sys('report_downloads', 'raa-image.png'), + file.path(my_tempdir, 'raa-image.png'), overwrite = TRUE) + } + else { + Report <- file.path(my_tempdir, "reportPdf.Rmd") + if (!dir.exists(file.path(my_tempdir, "images"))) + dir.create(file.path(my_tempdir, "images")) + file.copy(app_sys('report_downloads', 'reportPdf.Rmd'), + Report, + overwrite = TRUE) + file.copy(app_sys('report_downloads', 'header.tex'), + file.path(my_tempdir, 'header.tex'), + overwrite = TRUE) + file.copy(app_sys('report_downloads', 'fancyhdr.sty'), + file.path(my_tempdir, 'fancyhdr.sty'), + overwrite = TRUE) + file.copy(app_sys('report_downloads', 'read_html.lua'), + file.path(my_tempdir, "read_html.lua"), overwrite = TRUE) + file.copy(app_sys('report_downloads', 'images', 'user-tie.png'), + file.path(my_tempdir, "images", "user-tie.png"), + overwrite = TRUE) + file.copy(app_sys('report_downloads', 'images', 'user-shield.png'), + file.path(my_tempdir, "images", "user-shield.png"), + overwrite = TRUE) + file.copy(app_sys('report_downloads', 'images', 'calendar-alt.png'), + file.path(my_tempdir, "images", "calendar-alt.png"), + overwrite = TRUE) + file.copy(app_sys('report_downloads', 'raa-image.png'), + file.path(my_tempdir, 'raa-image.png'), overwrite = TRUE) + } + + fs <- c() + for (i in 1:n_pkgs) { + if (is.function(updateProgress)) + updateProgress(1, paste("Processing", pkg_lst[i])) + # Grab package name and version, then create filename and path. + # this_pkg <- "stringr" # for testing + selected_pkg <- get_pkg_info(pkg_lst[i], db_name) + this_pkg <- selected_pkg$name + this_ver <- selected_pkg$version + file_named <- glue::glue('{this_pkg}_{this_ver}_Risk_Assessment.{report_format}') + path <- file.path(my_tempdir, file_named) + + pkg_list <- list( + id = selected_pkg$id, + name = selected_pkg$name, + version = selected_pkg$version, + date_added = selected_pkg$date_added, + title = selected_pkg$title, + decision = selected_pkg$decision, + description = selected_pkg$description, + author = selected_pkg$author, + maintainer = selected_pkg$maintainer, + license = selected_pkg$license, + published = selected_pkg$published_on, + score = selected_pkg$score + ) + + # gather comments data + overall_comments <- get_overall_comments(this_pkg, db_name) + pkg_summary <- get_pkg_summary(this_pkg, db_name) + mm_comments <- get_mm_comments(this_pkg, db_name) + cm_comments <- get_cm_comments(this_pkg, db_name) + se_comments <- get_se_comments(this_pkg, db_name) + fe_comments <- get_fe_comments(this_pkg, db_name) + + # gather maint metrics & community metric data + mm_data <- get_metric_data(this_pkg, metric_class = "maintenance", db_name) + comm_data <- get_comm_data(this_pkg, db_name) + comm_cards <- build_comm_cards(comm_data, db_name) + downloads_plot <- build_comm_plotly(comm_data) + metric_tbl <- dbSelect("select * from metric", db_name = db_name) + + dep_metrics <- get_depends_data(this_pkg, db_name = db_name) + + dep_cards <- build_dep_cards(data = dep_metrics, loaded = loaded2_db$name, toggled = 0L) + + dep_table <- + if (nrow(dep_metrics) == 0) { + dplyr::tibble(package = character(), type = character(), version = character(), score = character()) + } else { + purrr::map_df(dep_metrics$name, ~get_versnScore(.x, loaded2_db, repo_pkgs)) %>% + right_join(dep_metrics, by = "name") %>% + select(package, type, version, score) %>% + arrange(package, type) %>% + distinct() + } + + # Render the report, passing parameters to the rmd file. + rmarkdown::render( + input = Report, + output_file = path, + clean = FALSE, + params = list(pkg = pkg_list, + report_includes = report_includes, + riskmetric_version = paste0(packageVersion("riskmetric")), + app_version = golem::get_golem_options('app_version'), + metric_weights = metric_weights, + user_name = user$name, + user_role = paste(user$role, collapse = ', '), + overall_comments = overall_comments, + pkg_summary = pkg_summary, + mm_comments = mm_comments, + cm_comments = cm_comments, + se_comments = se_comments, + fe_comments = fe_comments, + maint_metrics = mm_data, + com_metrics = comm_cards, + com_metrics_raw = comm_data, + downloads_plot_data = downloads_plot, + dep_cards = dep_cards, + dep_table = dep_table, + metric_tbl = metric_tbl + ) + ) + fs <- c(fs, path) # Save all the reports/ + } + + if (is.function(updateProgress)) + updateProgress(1, "**Finished**") + + fs +} + diff --git a/R/utils_build_cards.R b/R/utils_build_cards.R index bf8252596..2ff4326ed 100644 --- a/R/utils_build_cards.R +++ b/R/utils_build_cards.R @@ -50,7 +50,7 @@ metric_gauge <- function(score) { # could add id arg here #' @importFrom stats lm #' @keywords internal #' -build_comm_cards <- function(data){ +build_comm_cards <- function(data, db_name = golem::get_golem_options('assessment_db_name')){ cards <- dplyr::tibble( name = character(), @@ -119,7 +119,7 @@ build_comm_cards <- function(data){ # pull in some riskmetric data - comm <- get_metric_data(data$id[1], metric_class = 'community', golem::get_golem_options('assessment_db_name')) + comm <- get_metric_data(data$id[1], metric_class = 'community', db_name) # get downloads in the last year @@ -147,7 +147,7 @@ build_comm_cards <- function(data){ # get reverse dependency info - rev_deps <- get_assess_blob(data$id[1])$reverse_dependencies[[1]] + rev_deps <- get_assess_blob(data$id[1], db_name)$reverse_dependencies[[1]] comm_rev <- comm %>% filter(name == "reverse_dependencies") # new diff --git a/R/utils_get_db.R b/R/utils_get_db.R index 2a49f3aa4..08d117381 100644 --- a/R/utils_get_db.R +++ b/R/utils_get_db.R @@ -18,6 +18,7 @@ dbSelect <- function(query, db_name = golem::get_golem_options('assessment_db_na errFlag <- FALSE con <- DBI::dbConnect(RSQLite::SQLite(), db_name) + RSQLite::sqliteSetBusyHandler(con, 3000) tryCatch( expr = { rs <- DBI::dbSendQuery(con, glue::glue_sql(query, .envir = .envir, .con = con)) diff --git a/R/utils_insert_db.R b/R/utils_insert_db.R index 686e7f2a2..8ef1e4586 100644 --- a/R/utils_insert_db.R +++ b/R/utils_insert_db.R @@ -21,6 +21,7 @@ dbUpdate <- function(command, db_name = golem::get_golem_options('assessment_db_ errFlag <- FALSE con <- DBI::dbConnect(RSQLite::SQLite(), db_name) + RSQLite::sqliteSetBusyHandler(con, 3000) tryCatch({ rs <- DBI::dbSendStatement(con, glue::glue_sql(command, .envir = .envir, .con = con)) if (!is.null(params)) diff --git a/man/build_comm_cards.Rd b/man/build_comm_cards.Rd index 8dabc9638..5c4a324ed 100644 --- a/man/build_comm_cards.Rd +++ b/man/build_comm_cards.Rd @@ -4,7 +4,10 @@ \alias{build_comm_cards} \title{The 'Build Community Cards' function} \usage{ -build_comm_cards(data) +build_comm_cards( + data, + db_name = golem::get_golem_options("assessment_db_name") +) } \arguments{ \item{data}{a data.frame} diff --git a/tests/testthat/test-downloadHandler.R b/tests/testthat/test-downloadHandler.R index 6baf422e3..f2400eaa0 100644 --- a/tests/testthat/test-downloadHandler.R +++ b/tests/testthat/test-downloadHandler.R @@ -4,19 +4,27 @@ test_that("downloadHandler works", { expect_equal(app$get_value(input = "tabs"), "single") expect_equal(app$get_value(input = "downloadHandler_1-report_format"), "html") + app$click("downloadHandler_1-create_reports", timeout_ = 30*1000) + app$wait_for_idle() report <- app$get_download("downloadHandler_1-download_reports") expect_equal(tools::file_ext(report), "html") app$set_inputs(`downloadHandler_1-report_format` = "docx") + app$click("downloadHandler_1-create_reports", timeout_ = 30*1000) + app$wait_for_idle() report <- app$get_download("downloadHandler_1-download_reports") expect_equal(tools::file_ext(report), "docx") app$set_inputs(`downloadHandler_1-report_format` = "pdf") + app$click("downloadHandler_1-create_reports", timeout_ = 30*1000) + app$wait_for_idle() report <- app$get_download("downloadHandler_1-download_reports") expect_equal(tools::file_ext(report), "pdf") app$set_inputs(tabs = "multiple") expect_equal(app$get_value(input = "downloadHandler_2-report_format"), "html") + app$click("downloadHandler_2-create_reports", timeout_ = 30*1000) + app$wait_for_idle() report <- app$get_download("downloadHandler_2-download_reports") expect_equal(tools::file_ext(report), "zip") }) diff --git a/tests/testthat/test-reportPreview.R b/tests/testthat/test-reportPreview.R index 3e3d4ddbe..04377c016 100644 --- a/tests/testthat/test-reportPreview.R +++ b/tests/testthat/test-reportPreview.R @@ -36,6 +36,8 @@ test_that("Reactivity of reportPreview", { expect_equal(app$get_value(input = "reportPreview-downloadHandler-report_format"), "html") # download and check file type + app$click("reportPreview-downloadHandler-create_reports", timeout_ = 30*1000) + app$wait_for_idle() report <- app$get_download("reportPreview-downloadHandler-download_reports") app$wait_for_idle()