Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add progress indicator #320

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d2b2397
add progress indicator
maxheld83 Oct 14, 2021
2165d33
adapt change to notifications
maxheld83 Nov 10, 2021
e0a42df
Merge branch 'main' into pnot
maxheld83 Nov 10, 2021
3a5bf0b
notify about state of async jobs closes #88
maxheld83 Nov 11, 2021
a54e90b
add missing docs
maxheld83 Nov 11, 2021
990ad2c
block email inputs once send is underway
maxheld83 Nov 11, 2021
2c9db87
Merge branch 'main' into pnot
maxheld83 Nov 11, 2021
c4948ed
bump version number to dev
maxheld83 Nov 11, 2021
879e0db
give test more time to pass
maxheld83 Nov 23, 2021
867aa9d
add explanation
maxheld83 Nov 23, 2021
8d828bb
fix indentation
maxheld83 Nov 25, 2021
2b43e9a
add downstrack progress bars
maxheld83 Nov 29, 2021
e1d0771
upgrade muggle
maxheld83 Nov 29, 2021
04856db
fix bug in docs
maxheld83 Dec 1, 2021
b55ea8d
narrow down spurious warnings
maxheld83 Dec 2, 2021
a1d7ed3
emit knitr output
maxheld83 Dec 2, 2021
f3654e9
pass on knitr progress info
maxheld83 Dec 2, 2021
c015b62
reorg tests
maxheld83 Dec 2, 2021
bc59fff
add linebreak
maxheld83 Dec 6, 2021
128d848
migrate out test helper
maxheld83 Dec 6, 2021
28af705
streamline skeloton
maxheld83 Dec 8, 2021
f8cd888
only define plan at runtime #345
maxheld83 Dec 8, 2021
203a744
factor out spreadsheet generation
maxheld83 Dec 8, 2021
cd2c6fd
run test in efficient order
maxheld83 Dec 8, 2021
315b2fa
add test helpers for async
maxheld83 Dec 8, 2021
805f5da
skip temp install during rcmd check
maxheld83 Dec 9, 2021
152f621
loop test over all languages
maxheld83 Dec 9, 2021
e2742ec
assign lang first
maxheld83 Dec 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
shell: Rscript {0}
container:
# update muggle here and in Dockerfile
image: subugoe/muggle-buildtime-onbuild:0.1.2-20210716
image: subugoe/muggle-buildtime-onbuild:0.1.2-20211124
env:
MUGGLE_PKG_NAME: ${{ github.event.repository.name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
11 changes: 8 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: metacheck
Title: Crossref Metadata Compliance
Version: 0.3.0
Version: 0.3.1.9000
Authors@R:
c(
person(
Expand Down Expand Up @@ -85,7 +85,9 @@ Imports:
bslib,
curl,
crlite,
lobstr
lobstr,
progressr,
ellipsis
Suggests:
testthat,
subugoetheme,
Expand All @@ -95,7 +97,9 @@ Suggests:
htmltools,
knitr,
pkgdown,
downlit
downlit,
remotes,
usethis
URL: https://subugoe.github.io/metacheck, https://github.com/subugoe/metacheck
BugReports: https://github.com/subugoe/metacheck/issues
Remotes:
Expand All @@ -109,4 +113,5 @@ Remotes:
r-lib/downlit@47e30dbe7650bac683c979e73608180813ce660c
Config/testthat/edition: 3
Config/testthat/parallel: true
Config/testthat/start-first: communicate, email, import
Config/wama/defaultShinyApp: mcApp()
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ARG MUGGLE_TAG=0.1.2-20210716
ARG MUGGLE_TAG=0.1.2-20211124
FROM subugoe/muggle-buildtime-onbuild:${MUGGLE_TAG} as buildtime
FROM subugoe/muggle-runtime-onbuild:${MUGGLE_TAG} as runtime
ENV R_FUTURE_PLAN=multicore
CMD shinycaas::shiny_opts_az(); metacheck::runMetacheck()
8 changes: 5 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export("%>%")
export(accumulate_pred_trans)
export(add_attachment_mc)
export(assert_metacheckable)
export(auth_cr)
export(auth_mailjet)
Expand All @@ -11,11 +12,14 @@ export(cr_compliance_overview)
export(cr_funder_df)
export(cr_has_orcid)
export(cr_tdm_df)
export(create_and_attach_ss)
export(create_ss)
export(doi_examples)
export(draft_report)
export(emailReport)
export(emailReportServer)
export(emailReportUI)
export(email_async)
export(funder_metrics)
export(get_cr_md)
export(get_delayed_license)
Expand All @@ -37,18 +41,16 @@ export(mc_long_docs)
export(mc_long_docs_string)
export(mc_render_email)
export(mc_translator)
export(md_data_attachment)
export(metrics_overview)
export(pretests)
export(render_and_send)
export(render_and_send_async)
export(render_report)
export(report_metacheckable)
export(runMetacheck)
export(smtp_send_mc)
export(tabulate_metacheckable)
export(tdm_metrics)
export(vor_issue)
export(write_xlsx_mc)
import(dplyr)
import(purrr)
import(tidyr)
Expand Down
5 changes: 4 additions & 1 deletion R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ auth_mailjet <- function() {
username = mailjet_username
),
error = function(x) {
warning("Could not find Mailjet SMTPs credentials; you may not be send out email.")
warning(
"Could not find Mailjet SMTPs credentials;
you may not be able to send out email."
)
return(character(1))
}
)
Expand Down
1 change: 0 additions & 1 deletion R/communicate.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ runMetacheck <- function(...) shiny::runApp(appDir = mcApp(), ...)
#' @family communicate
#' @export
mcApp <- function() {
future::plan(future::multicore, workers = 20L)
shiny::shinyApp(
ui = mcAppUI(),
server = mcAppServer
Expand Down
198 changes: 100 additions & 98 deletions R/email.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ NULL

#' @describeIn email Compose complete mail
#' @inheritDotParams mc_render_email
#' @inheritParams biblids::doiEntryUI
#' @export
mc_compose_email <- function(dois,
mc_compose_email <- function(dois = doi_examples$good[1:10],
translator = mc_translator(),
...) {
mc_body_block(dois = dois, translator = translator, ...) %>%
mc_compose_email_outer(translator = translator) %>%
blastula::add_attachment(
md_data_attachment(dois = dois),
filename = translator$translate("mc_individual_results.xlsx")
)
create_and_attach_ss(email = ., dois = dois, translator = translator)
}

mc_body_block <- function(dois, translator = mc_translator(), ...) {
Expand Down Expand Up @@ -136,56 +134,21 @@ block_text_centered_vec <- function(...) {

#' @describeIn email Render email body (inner content)
#' @inheritParams report
#' @inheritParams blastula::render_email
#' @inheritDotParams blastula::render_email
#' @export
mc_render_email <- function(dois = doi_examples$good[1:10],
translator = mc_translator(),
quiet = !interactive(),
...) {
# suppression is dangerous hack-fix for
# https://github.com/subugoe/metacheck/issues/138
# otherwise, tests are illegibly noisy
suppressWarnings(
blastula::render_email(
input = path_report_rmd(lang = translator$get_translation_language()),
render_options = list(
params = list(
dois = dois,
translator = translator
)
),
...
)
)
}

#' @describeIn email Render and send
#' @inheritDotParams mc_compose_email
#' @inheritParams smtp_send_mc
#' @export
render_and_send <- function(to, translator = mc_translator(), ...) {
email <- mc_compose_email(
translator = translator,
blastula::render_email(
input = path_report_rmd(lang = translator$get_translation_language()),
render_options = list(
params = list(dois = dois)
),
quiet = quiet,
...
)
smtp_send_mc(to = to, email = email, translator = translator)
}

#' @describeIn email Render and send asynchronously
#' @export
render_and_send_async <- function(...) {
# this is a workaround to enable async when developing on macOS
# macOS forked processes apparently cannot read keychain (makes sense)
# so we have to pass in the password manually
auth_mailjet()
mj_pw <- Sys.getenv("MAILJET_SMTP_PASSWORD")
promises::future_promise(
expr = {
Sys.setenv("MAILJET_SMTP_PASSWORD" = mj_pw)
render_and_send(...)
},
seed = TRUE
)
NULL
}

# sending ====
Expand All @@ -211,7 +174,7 @@ smtp_send_mc <- function(email = blastula::prepare_test_message(),
credentials = credentials,
...
)
invisible(email) # best practice
invisible(email) # best practice for funs called for side effects
}

#' Get credentials for smtp
Expand Down Expand Up @@ -361,68 +324,107 @@ emailReportServer <- function(id,
})
shiny::observeEvent(input$send, {
if (iv$is_valid()) {
shiny::showModal(modalDialog(
title = translWithLang()$translate(
"You have successfully sent your DOIs"
),
glue::glue(
translWithLang()$translate(
"You will receive an email with your report within the next 45 minutes. "
),
translWithLang()$translate(
"Please check your SPAM folder. "
)
),
easyClose = TRUE,
footer = NULL
))
render_and_send_async(
toggle_email_input_elements()
promise_list <- email_async(
to = input$recipient,
dois = dois(),
translator = translWithLang()
)
promises::then(
promise_list$done,
onFulfilled = function(value) toggle_email_input_elements()
)
}
})
}
)
}

# excel attachment ====
#' @describeIn emailReport Dis/enable all input elements in the module
toggle_email_input_elements <- function() {
shinyjs::toggleState("recipient")
shinyjs::toggleState("gdpr_consent")
shinyjs::toggleState("send")
}

#' Make Spreadsheet attachment
#' Creates an excel spreadsheet with individual-level results.
#'
#' @details `r metacheck::mc_long_docs_string("spreadsheet.md")`
#'
#' @param dois character, *all* submitted dois
#' @param df compliance data from [cr_compliance_overview()]
#' @inheritParams writexl::write_xlsx
#'
#' @return path to the created file
#'
#' @describeIn emailReport Promise of a rendered and send email
#' Emits notifications and progress bar updates.
#' @inheritParams mc_compose_email
#' @inheritDotParams mc_compose_email
#' @inheritParams smtp_send_mc
#' @export
#' @family communicate
md_data_attachment <- function(dois,
df = cr_compliance_overview(get_cr_md(
dois[is_metacheckable(dois)]
)),
path = fs::file_temp(ext = "xlsx")) {
is_compliance_overview_list(df)
df[["pretest"]] <- tibble::tibble(
# writexl does not know vctrs records
doi = as.character(biblids::as_doi(dois)),
tabulate_metacheckable(dois)
email_async <- function(to, translator = mc_translator(), ...) {
shiny::showNotification(
ui = glue::glue(
translator$translate("Your email report is being prepared."),
translator$translate(
"You can close this window or wait for completion. "
),
translator$translate("Remember to check your SPAM folder.")
),
duration = NULL,
id = "notifi_start",
type = "message"
)
writexl::write_xlsx(
x = df,
path = path
pb <- shiny::Progress$new()
pb$set(value = 0, message = translator$translate("Starting ..."))
# this is strictly out of order and is only needed later
# but run here, b/c it actually need not be async,
# so placing this here is cleaner to read
pb$set(
value = 1/4,
message = translator$translate("Authenticating email relay ...")
)
}

#' Data is available
#' @noRd
is_compliance_overview_list <- function(x) {
assertthat::assert_that(x %has_name% c("cr_overview", "cc_license_check"),
msg = "No Compliance Data to attach, compliance data from [cr_compliance_overview()]"
# this is a workaround to enable async when developing on macOS
# macOS forked processes apparently cannot read keychain (makes sense)
# so we have to pass in the password manually
auth_mailjet()
mj_pw <- Sys.getenv("MAILJET_SMTP_PASSWORD")
promise_email <- promises::future_promise(
expr = mc_compose_email(translator = translator, ...),
seed = TRUE
)
pb$set(
value = 2/4,
message = translator$translate("Composing email ..."),
detail = translator$translate("This can take several minutes.")
)
promise_sent <- promises::then(
promise_email,
onFulfilled = function(value) {
pb$set(
value = 3/4,
message = translator$translate("Sending email ...")
)
promises::future_promise(
expr = {
Sys.setenv("MAILJET_SMTP_PASSWORD" = mj_pw)
smtp_send_mc(to = to, email = value, translator = translator)
},
seed = TRUE
)
}
)
id_notifi_done <- "notifi_done"
promise_done <- promises::then(
promise_sent,
onFulfilled = function(value) {
pb$set(value = 4/4, message = translator$translate("Done."))
pb$close()
shiny::removeNotification("notifi_start")
shiny::showNotification(
ui = glue::glue(
translator$translate("Your report is in your email inbox. "),
translator$translate("Remember to check your SPAM folder. ")
),
duration = NULL,
closeButton = TRUE,
id = id_notifi_done,
type = "message"
)
value
}
)
# both are needed upstream
list(done = promise_done, id_notifi = id_notifi_done)
}
8 changes: 6 additions & 2 deletions R/import.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ looped_possibly_cr_works_field <- function(x, field, ...) {
x <- biblids::as_doi(x)
# remove this hackfix https://github.com/subugoe/metacheck/issues/182
x <- as.character(x)
pb <- progressr::progressor(
along = x,
message = "Querying Crossref API (works endpoint) ...",
label = "memoised_possibly_cr_works_field"
)
res <- purrr::map_chr(
x,
memoised_possibly_cr_works_field,
field = field,
function(x) {pb(); memoised_possibly_cr_works_field(x, field = field, ...)},
...
)
res
Expand Down
5 changes: 3 additions & 2 deletions R/metrics_funder.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ funder_metrics <- function(funder_info = NULL) {
mutate(name = ifelse(is.na(.data$name), "No funding info", .data$name)) %>%
mutate(name = forcats::fct_lump_prop(.data$name, prop = 0.03, other_level = "Other funders")) %>%
mutate(name = forcats::fct_infreq(.data$name)) %>%
mutate(name = forcats::fct_relevel(.data$name, "Other funders", after = Inf)) %>%
mutate(name = forcats::fct_relevel(.data$name, "No funding info", after = Inf))
# TODO hack fix to avoid spurious warnings https://github.com/subugoe/metacheck/issues/344
suppressWarnings(mutate(name = forcats::fct_relevel(.data$name, "Other funders", after = Inf))) %>%
suppressWarnings(mutate(name = forcats::fct_relevel(.data$name, "No funding info", after = Inf)))
} else {
out <-funder_info %>%
mutate(name = ifelse(is.na(.data$name), "No funding info", .data$name)) %>%
Expand Down
Loading