Skip to content

Commit

Permalink
Merge branch 'main' into 169_wrap_rcode@main
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikeyakirar committed Oct 3, 2023
2 parents 706d504 + b82c2ac commit 8fa2e3a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: teal.reporter
Title: Reporting Tools for 'shiny' Modules
Version: 0.2.1.9005
Date: 2023-09-29
Version: 0.2.1.9006
Date: 2023-10-03
Authors@R: c(
person("Dawid", "Kaledkowski", , "[email protected]", role = "cre"),
person("Maciej", "Nasinski", role = "aut"),
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# teal.reporter 0.2.1.9005
# teal.reporter 0.2.1.9006

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

* Supports automatic `Rcode` formatting using the suggested `formatR` package in reports.

Expand All @@ -11,6 +13,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.

0 comments on commit 8fa2e3a

Please sign in to comment.