diff --git a/R/module_init_data.R b/R/module_init_data.R index 8808acb9fe..376b0aeebf 100644 --- a/R/module_init_data.R +++ b/R/module_init_data.R @@ -92,10 +92,17 @@ srv_init_data <- function(id, data) { hashes <- .get_hashes_code(data) data_teal_report <- as(data, "teal_report") if (!inherits(data, "teal_report")) { + current_card <- lapply( + teal.reporter::teal_card(data_teal_report), + function(x) { + if (inherits(x, "code_chunk")) { + attr(x, "always_keep") <- TRUE + x + } + } + ) teal.reporter::teal_card(data_teal_report) <- c( - teal.reporter::teal_card(), - "## Code preparation", - teal.reporter::teal_card(data_teal_report) + teal.reporter::teal_card("## Data preparation"), current_card ) } tdata <- do.call( diff --git a/R/teal_data_utils.R b/R/teal_data_utils.R index c461bc16c8..ffedc07e57 100644 --- a/R/teal_data_utils.R +++ b/R/teal_data_utils.R @@ -24,7 +24,7 @@ NULL teal.reporter::teal_card(data) <- c( teal.reporter::teal_card(data), "## Data filtering", - teal.reporter::code_chunk(code) + teal.reporter::code_chunk(code, always_keep = TRUE) ) methods::validObject(data) } @@ -55,11 +55,14 @@ NULL inherits(this, "code_chunk") && identical(attr(x[[l]], "params"), attr(this, "params")) ) { + always_keep <- (attr(x[[l]], "always_keep", exact = TRUE) %||% FALSE) || + (attr(this, "always_keep", exact = TRUE) %||% FALSE) x[[length(x)]] <- do.call( teal.reporter::code_chunk, args = c( list(code = paste(x[[l]], this, sep = "\n")), - attr(x[[l]], "params") + attr(x[[l]], "params"), + list(always_keep = always_keep) ) ) x