From 8688465a104c1ae0f7cf069476465f03eb67ea90 Mon Sep 17 00:00:00 2001 From: Aleksander Chlebowski Date: Tue, 23 Apr 2024 19:06:29 +0200 Subject: [PATCH 1/4] add env argument --- R/AddCardModule.R | 9 +++++++-- R/SimpleReporter.R | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/R/AddCardModule.R b/R/AddCardModule.R index 91825da21..8d04050e8 100644 --- a/R/AddCardModule.R +++ b/R/AddCardModule.R @@ -83,10 +83,11 @@ add_card_button_ui <- function(id) { #' @rdname add_card_button #' @export -add_card_button_srv <- function(id, reporter, card_fun) { +add_card_button_srv <- function(id, reporter, card_fun, env) { checkmate::assert_function(card_fun) checkmate::assert_class(reporter, "Reporter") - checkmate::assert_subset(names(formals(card_fun)), c("card", "comment", "label"), empty.ok = TRUE) + checkmate::assert_subset(names(formals(card_fun)), c("card", "comment", "label", "env"), empty.ok = TRUE) + checkmate::assert_environment(env, null.ok = TRUE) shiny::moduleServer(id, function(input, output, session) { shiny::setBookmarkExclude(c( @@ -160,6 +161,7 @@ add_card_button_srv <- function(id, reporter, card_fun) { has_card_arg <- "card" %in% card_fun_args_nams has_comment_arg <- "comment" %in% card_fun_args_nams has_label_arg <- "label" %in% card_fun_args_nams + has_env_arg <- "label" %in% card_fun_args_nams arg_list <- list() @@ -169,6 +171,9 @@ add_card_button_srv <- function(id, reporter, card_fun) { if (has_label_arg) { arg_list <- c(arg_list, list(label = input$label)) } + if (has_env_arg && !is.null(env)) { + arg_list <- c(arg_list, env = env) + } if (has_card_arg) { # The default_card is defined here because formals() returns a pairedlist object diff --git a/R/SimpleReporter.R b/R/SimpleReporter.R index ce11071eb..6bc6711ec 100644 --- a/R/SimpleReporter.R +++ b/R/SimpleReporter.R @@ -69,11 +69,12 @@ simple_reporter_srv <- function(id, author = "NEST", title = "Report", date = as.character(Sys.Date()), output = "html_document", toc = FALSE - )) { + ), + env) { shiny::moduleServer( id, function(input, output, session) { - add_card_button_srv("add_report_card_simple", reporter = reporter, card_fun = card_fun) + add_card_button_srv("add_report_card_simple", reporter = reporter, card_fun = card_fun, env = env) download_report_button_srv( "download_button_simple", reporter = reporter, From 0d4570c8eaea6f851cb031f832a249acbb9c763b Mon Sep 17 00:00:00 2001 From: Aleksander Chlebowski Date: Tue, 23 Apr 2024 19:06:51 +0200 Subject: [PATCH 2/4] allow ellipsis in card_fun --- R/AddCardModule.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/AddCardModule.R b/R/AddCardModule.R index 8d04050e8..66e6b1145 100644 --- a/R/AddCardModule.R +++ b/R/AddCardModule.R @@ -86,7 +86,7 @@ add_card_button_ui <- function(id) { add_card_button_srv <- function(id, reporter, card_fun, env) { checkmate::assert_function(card_fun) checkmate::assert_class(reporter, "Reporter") - checkmate::assert_subset(names(formals(card_fun)), c("card", "comment", "label", "env"), empty.ok = TRUE) + checkmate::assert_subset(names(formals(card_fun)), c("card", "comment", "label", "env", "..."), empty.ok = TRUE) checkmate::assert_environment(env, null.ok = TRUE) shiny::moduleServer(id, function(input, output, session) { From 45faca2c42bed3ec9892886c6c80ee76b0c854c2 Mon Sep 17 00:00:00 2001 From: Aleksander Chlebowski Date: Wed, 24 Apr 2024 09:49:36 +0200 Subject: [PATCH 3/4] no need for ... in card function --- R/AddCardModule.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/AddCardModule.R b/R/AddCardModule.R index 66e6b1145..8d04050e8 100644 --- a/R/AddCardModule.R +++ b/R/AddCardModule.R @@ -86,7 +86,7 @@ add_card_button_ui <- function(id) { add_card_button_srv <- function(id, reporter, card_fun, env) { checkmate::assert_function(card_fun) checkmate::assert_class(reporter, "Reporter") - checkmate::assert_subset(names(formals(card_fun)), c("card", "comment", "label", "env", "..."), empty.ok = TRUE) + checkmate::assert_subset(names(formals(card_fun)), c("card", "comment", "label", "env"), empty.ok = TRUE) checkmate::assert_environment(env, null.ok = TRUE) shiny::moduleServer(id, function(input, output, session) { From 87e6a6e232c8e58a0f52674e4203108ddf4b26dc Mon Sep 17 00:00:00 2001 From: Aleksander Chlebowski Date: Wed, 24 Apr 2024 10:16:07 +0200 Subject: [PATCH 4/4] clear white space --- R/SimpleReporter.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/SimpleReporter.R b/R/SimpleReporter.R index 7f586d03b..a50794c7d 100644 --- a/R/SimpleReporter.R +++ b/R/SimpleReporter.R @@ -66,15 +66,15 @@ simple_reporter_srv <- function( card_fun, global_knitr = getOption("teal.reporter.global_knitr"), rmd_output = c( - "html" = "html_document", + "html" = "html_document", "pdf" = "pdf_document", - "powerpoint" = "powerpoint_presentation", + "powerpoint" = "powerpoint_presentation", "word" = "word_document" ), rmd_yaml_args = list( - author = "NEST", + author = "NEST", title = "Report", - date = as.character(Sys.Date()), + date = as.character(Sys.Date()), output = "html_document", toc = FALSE ),