From 61326d834fe1d19d8a8858652cd16a639654aaca Mon Sep 17 00:00:00 2001 From: vedhav Date: Mon, 4 Nov 2024 20:46:49 +0530 Subject: [PATCH] feat: improve the print for modules --- R/modules.R | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/R/modules.R b/R/modules.R index 59ad3e5d97..8cafecc515 100644 --- a/R/modules.R +++ b/R/modules.R @@ -323,18 +323,26 @@ modules <- function(..., label = "root") { #' @rdname teal_modules #' @export format.teal_module <- function(x, indent = 0, ...) { - paste0(paste(rep(" ", indent), collapse = ""), "+ ", x$label, "\n", collapse = "") -} - - -#' @rdname teal_modules -#' @export -print.teal_module <- function(x, ...) { - cat(format(x, ...)) - invisible(x) + indent_str <- paste(rep(" ", indent), collapse = "") + bookmarkable <- ifelse(isTRUE(attr(x, "teal_bookmarkable")), "Yes", "No") + reportable <- ifelse("reporter" %in% names(formals(x$server)), "Yes", "No") + transformers <- if (length(x$transformers) > 0) { + paste0("Transformers: ", paste(sapply(x$transformers, function(t) t$label), collapse = ", ")) + } else { + "Transformers: None" + } + paste0( + indent_str, "+ ", x$label, "\n", + indent_str, " - datanames: ", paste(x$datanames, collapse = ", "), "\n", + indent_str, " - bookmarkable: ", bookmarkable, "\n", + indent_str, " - reportable: ", reportable, "\n", + indent_str, " - ui_args: ", ifelse(is.null(x$ui_args), "None", paste(names(x$ui_args), collapse = ", ")), "\n", + indent_str, " - server_args: ", ifelse(is.null(x$server_args), "None", paste(names(x$server_args), collapse = ", ")), "\n", + indent_str, " - ", transformers, "\n", + collapse = "" + ) } - #' @rdname teal_modules #' @export format.teal_modules <- function(x, indent = 0, ...) { @@ -347,6 +355,20 @@ format.teal_modules <- function(x, indent = 0, ...) { ) } +#' @rdname teal_modules +#' @export +print.teal_module <- function(x, ...) { + cat(format(x, ...)) + invisible(x) +} + +#' @rdname teal_modules +#' @export +print.teal_modules <- function(x, ...) { + cat(format(x, ...)) + invisible(x) +} + #' @param modules (`teal_module` or `teal_modules`) #' @rdname teal_modules #' @examples @@ -380,11 +402,6 @@ set_datanames <- function(modules, datanames) { modules } -#' @rdname teal_modules -#' @export -print.teal_modules <- print.teal_module - - # utilities ---- ## subset or modify modules ----