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

Support Load Reporter #1120

Merged
merged 18 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ S3method(ui_nested_tabs,teal_modules)
S3method(within,teal_data_module)
export("%>%")
export(TealReportCard)
export(TealSlicesBlock)
export(as.teal_slices)
export(as_tdata)
export(build_app_title)
Expand Down
7 changes: 5 additions & 2 deletions R/module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,12 @@ srv_teal <- function(id, modules, teal_data_rv, filter = teal_slices()) {
}
)

reporter <- teal.reporter::Reporter$new()
reporter <- teal.reporter::Reporter$new()$set_id(attr(filter, "app_id"))
if (is_arg_used(modules, "reporter") && length(extract_module(modules, "teal_module_previewer")) == 0) {
modules <- append_module(modules, reporter_previewer_module())
modules <- append_module(
modules,
reporter_previewer_module(server_args = list(previewer_buttons = c("download", "reset")))
)
}

env <- environment()
Expand Down
43 changes: 32 additions & 11 deletions R/teal_reporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ TealReportCard <- R6::R6Class( # nolint: object_name.
private = list()
)

#' @title `RcodeBlock`
#' @keywords internal
#' @title `TealSlicesBlock`
#' @docType class
#' @description
#' Specialized `TealSlicesBlock` block for managing filter panel content in reports.
#'
#' @export
TealSlicesBlock <- R6::R6Class( # nolint: object_name_linter.
classname = "TealSlicesBlock",
inherit = teal.reporter:::TextBlock,
Expand Down Expand Up @@ -142,21 +146,38 @@ TealSlicesBlock <- R6::R6Class( # nolint: object_name_linter.
private$teal_slices <- content
invisible(self)
},
#' @description Create the `RcodeBlock` from a list.
#' @param x (named `list`) with two fields `c("text", "params")`.
#' Use the `get_available_params` method to get all possible parameters.
#' @description Create the `TealSlicesBlock` from a list.
#'
#' @param x (`named list`) with two fields `text` and `style`.
#' Use the `get_available_styles` method to get all possible styles.
#'
#' @return `self`, invisibly.
#' @examples
#' TealSlicesBlock <- getFromNamespace("TealSlicesBlock", "teal")
#' block <- TealSlicesBlock$new()
#' block$from_list(list(text = "sth", style = "default"))
#'
from_list = function(x) {
checkmate::assert_list(x)
checkmate::assert_names(names(x), must.include = c("teal_slices"))
self$set_content(x$teal_slices)
checkmate::assert_names(names(x), must.include = c("text", "style"))
super$set_content(x$text)
super$set_style(x$style)
invisible(self)
},
#' @description Convert the `RcodeBlock` to a list.
#' @return named `list` with a text and `params`.

#' @description Convert the `TealSlicesBlock` to a list.
#'
#' @return `named list` with a text and style.
#' @examples
#' TealSlicesBlock <- getFromNamespace("TealSlicesBlock", "teal")
#' block <- TealSlicesBlock$new()
#' block$to_list()
#'
to_list = function() {
list(teal_slices = private$teal_slices)
content <- self$get_content()
list(
text = if (length(content)) content else "",
style = self$get_style()
)
}
),
private = list(
Expand Down
58 changes: 49 additions & 9 deletions man/TealSlicesBlock.Rd

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

3 changes: 2 additions & 1 deletion tests/testthat/test-teal_reporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ testthat::test_that("TealSlicesBlock$to_list returns list containing teal_slices
block <- TealSlicesBlock$new(tss)
testthat::expect_identical(
block$to_list(),
list(teal_slices = tss)
list(text = "- Dataset name: a\n Variable name: b\n", style = "verbatim")
)
})

Expand All @@ -110,3 +110,4 @@ testthat::test_that("TealSlicesBlock$from_list retains states from a list", {
block2$from_list(block1$to_list())
testthat::expect_identical(block1$get_content(), block2$get_content())
})

Loading