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

198 Include user's card labels when generating the report #219

Merged
merged 11 commits into from
Oct 3, 2023
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# teal.reporter 0.2.1.9005

* `add_card_button_srv` allows to specify `card_fun` with `label` parameter for card's title & content customization.

# teal.reporter 0.2.1

### Miscellaneous
Expand All @@ -9,6 +11,8 @@
* Fixed CRAN requirements for the first CRAN submission.
* Removed manual pages for non-exported objects.

* Fixed CRAN requirements for the first CRAN submission.

# teal.reporter 0.2.0

### New features
Expand Down
22 changes: 13 additions & 9 deletions R/AddCardModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ add_card_button_ui <- function(id) {
#'
#' @param id `character(1)` this `shiny` module's id.
#' @param reporter [`Reporter`] instance.
#' @param card_fun `function` which returns a [`ReportCard`] instance,
#' the function has optional `card` and `comment` arguments.
#' If the `card` argument is added then the `ReportCard` instance is automatically created for the user.
#' If the `comment` argument is not specified then it is added automatically at the end of the Card.
#' The card name set by default in `card_fun` will be overcome by the `label` input which will be set automatically
#' when adding a card.
#'
#' @param card_fun `function` which returns a [`ReportCard`] instance. It can have optional `card`, `comment` and
#' `label` parameters. If `card` parameter is added, then the `ReportCard` instance is created for the user.
#' Use `comment` parameter to pass it's value whenever you prefer with `card$append_text()` - if `card_fun` does not
#' have `comment` parameter, then `comment` from `Add Card UI` module will be added at the end of the content of the
#' card. If `label` parameter is provided, you can use it to customize appearance of the `card name` and use if to
#' specify `card` content with `card$append_text()` - if `card_fun` does not have `label` parameter, then `card name`
#' will be set to the name passed in `Add Card UI` module, but no text will be added to the content of the `card`.
#'
#' @return `shiny::moduleServer`
#' @export
add_card_button_srv <- function(id, reporter, card_fun) {
checkmate::assert_function(card_fun)
checkmate::assert_class(reporter, "Reporter")
checkmate::assert_subset(names(formals(card_fun)), c("card", "comment"), empty.ok = TRUE)
checkmate::assert_subset(names(formals(card_fun)), c("card", "comment", "label"), empty.ok = TRUE)

shiny::moduleServer(
id,
Expand Down Expand Up @@ -151,12 +151,16 @@ add_card_button_srv <- function(id, reporter, card_fun) {
card_fun_args_nams <- names(formals(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

arg_list <- list()

if (has_comment_arg) {
arg_list <- c(arg_list, list(comment = input$comment))
}
if (has_label_arg) {
arg_list <- c(arg_list, list(label = input$label))
}

if (has_card_arg) {
# The default_card is defined here because formals() returns a pairedlist object
Expand Down Expand Up @@ -191,7 +195,7 @@ add_card_button_srv <- function(id, reporter, card_fun) {
card$append_text(input$comment)
}

if (length(input$label) == 1 && input$label != "") {
if (!has_label_arg && length(input$label) == 1 && input$label != "") {
card$set_name(input$label)
}

Expand Down
13 changes: 7 additions & 6 deletions man/add_card_button_srv.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.