Skip to content

{teal} module returns a teal_report object that extends from teal_data #1541

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

Open
wants to merge 116 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
96e3945
push local changes
vedhav Sep 17, 2024
7f56567
Merge branch 'main' into test@bslib@main
vedhav Sep 24, 2024
20bb0f0
feat: add additional sidebar toggle buttons
vedhav Sep 26, 2024
2c36c7b
feat: show three different tabs types for different module depths
vedhav Sep 26, 2024
45d0f1e
chore: add bslib package ns
vedhav Sep 26, 2024
52b7fc7
Merge branch 'main' into test@bslib@main
vedhav Sep 27, 2024
85622df
push local style changes
vedhav Oct 3, 2024
4881050
Merge remote-tracking branch 'origin/main' into test@bslib@main
vedhav Oct 3, 2024
8a12408
reposition the validated message div
vedhav Oct 3, 2024
910c26d
bold accordion titles
vedhav Oct 3, 2024
3279b6e
fix unwanted padding created by hidden validation message div
vedhav Oct 3, 2024
e7346fd
make sidebar width customizable using options
vedhav Oct 4, 2024
a616392
icon changes
vedhav Oct 7, 2024
0716caf
fix: make the filter mapping popup concise
vedhav Oct 17, 2024
813d5b5
Merge branch 'main' into test@bslib@main
vedhav Oct 17, 2024
e705f36
improve the sidebar distinction
vedhav Oct 18, 2024
21e3955
user feedback changes
vedhav Oct 22, 2024
486b565
Merge branch 'main' into test@bslib@main
vedhav Dec 11, 2024
3a1b5d6
Merge branch 'main' into test@bslib@main
vedhav Feb 13, 2025
36c2561
fix: remove unused component
vedhav Feb 13, 2025
2d5d3a6
report card handled by teal
gogonzo Feb 24, 2025
fe0545e
simplify
gogonzo Feb 24, 2025
333a87c
Merge main to test@bslib@main (#1497)
m7pr Feb 24, 2025
86391e4
feat: add remote dependencies
vedhav Feb 25, 2025
454d49e
revert teal.reporter redesign changes
m7pr Feb 26, 2025
620e5ba
bring back teal.reporter redesign changes
m7pr Feb 26, 2025
17f5a4a
update Remotes branch names
m7pr Feb 26, 2025
df3a62a
change add_card_button_srv -> add_document_button_srv
m7pr Feb 26, 2025
9f91260
add dev versions to teal dev dependencies
m7pr Feb 26, 2025
2bf6481
add dev versions to dependencies
m7pr Feb 26, 2025
06f2898
fix: bslib changes
vedhav Mar 3, 2025
59b3a15
bring add_document_button_srv to teal
m7pr Mar 4, 2025
c2388eb
make it a named list
m7pr Mar 4, 2025
466f0e7
Merge branch 'test@bslib@main' into redesign@main
vedhav Mar 4, 2025
9990dca
attempt on S3 class directly in teal
m7pr Mar 4, 2025
c3538e5
Merge branch 'redesign@main' of https://github.com/insightsengineerin…
m7pr Mar 4, 2025
c5301ff
compact to_markdown
m7pr Mar 4, 2025
ec60f50
bring back load button to reporter previewer
m7pr Mar 9, 2025
eb9abf3
change knitr to lenght1
m7pr Mar 9, 2025
72456fc
Merge branch 'main' into redesign@main
m7pr Mar 13, 2025
366def0
Update DESCRIPTION
m7pr Mar 13, 2025
35d4101
unify remotes
m7pr Mar 13, 2025
2667426
element to markdown not needed in teal
m7pr Mar 24, 2025
8729daa
cleanup NAMESPACE
m7pr Mar 25, 2025
7a5e099
extend example_module to handle report_card
m7pr Mar 25, 2025
0022f0d
extend shinytest2 tests for new teal reporter previewer
m7pr Mar 25, 2025
c0b9836
prototype of modify_teal_module_report
m7pr Apr 2, 2025
795a246
workout modify_teal_module_output
m7pr Apr 9, 2025
30118ec
introduce reporter parameter, so that you can disable it globally, or…
m7pr Apr 10, 2025
5829d61
Merge branch 'main' into redesign@main
m7pr Apr 25, 2025
4daffe4
bring back comments to addcard modal
m7pr Apr 30, 2025
ec5141a
clone reporter
gogonzo May 2, 2025
ea2c7e5
fix error when report is NULL (no method NULL$clone)
gogonzo May 5, 2025
2fad140
- always add report_previewer_module
gogonzo May 5, 2025
a8201af
disable_report instead of nullify_teal_module_report_card
gogonzo May 5, 2025
0201c7a
- rename modifiers
gogonzo May 6, 2025
4bf6e99
reload docs
gogonzo May 6, 2025
6cf260d
feat: move the reporter button
vedhav May 6, 2025
8be8963
prevent adding a card with the existing name
m7pr May 7, 2025
ef03a5b
fix reactivity
gogonzo May 8, 2025
4ae9720
Merge remote-tracking branch 'origin/main' into redesign@main
gogonzo May 8, 2025
35d3ae2
restart add card modal becuase the save button gets disabled after a …
m7pr May 8, 2025
0396d61
Merge branch 'redesign@main' of https://github.com/insightsengineerin…
m7pr May 8, 2025
ab96d22
enable add_card button after unsuccessful card addition
m7pr May 8, 2025
0372479
documentation and checks for modify_reactive_output
m7pr May 8, 2025
18b524e
[skip style] [skip vbump] Restyle files
github-actions[bot] May 11, 2025
6c92309
feat: move the reporter button outside the teal module
vedhav May 13, 2025
d1360e5
Minor changes from PR review
averissimo May 15, 2025
93cd49c
feat: use common structure for js autofocus input and enter to submit
averissimo May 15, 2025
a47a24a
chore: simplification of code into moduleServers
averissimo May 15, 2025
a6d3a8c
Merge branch 'pr@redesign@main' into redesign@main
averissimo May 15, 2025
0857eb2
chore: code trimming
averissimo May 15, 2025
8330ddb
fix: use trimmed named to store card
averissimo May 15, 2025
e90a5d5
revert: back to @ instead of %40 due to pak error
averissimo May 16, 2025
835cf0f
collapse subsequent chunks
gogonzo May 20, 2025
05c2255
Improves `ReportDocument` editor (#1536)
averissimo May 27, 2025
a803de7
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] May 27, 2025
bacf4cc
Merge branch 'teal_data_report' into teal_reportable
gogonzo May 27, 2025
21e400a
typo
gogonzo May 27, 2025
6c62626
convert teal_data to reportable
gogonzo May 27, 2025
40d5147
fix modify_reactive_output
gogonzo May 27, 2025
daa23ad
rename classes
gogonzo May 27, 2025
693c8e5
rename missing
gogonzo May 27, 2025
9f6965a
fix srv_reporter_previewer_tab to work with reactive output
gogonzo May 28, 2025
3ca11ab
reload docs
gogonzo May 28, 2025
45da1b4
after function
gogonzo May 28, 2025
bcab748
remove docs of modify_reactive_output
gogonzo May 28, 2025
8a1e9d3
Don't append filter panel code if no filters applied
gogonzo May 28, 2025
a19a367
chore: last of consisent naming
averissimo May 28, 2025
78ad8b2
fix: revert temporary fix that shouldn't have been pushed
averissimo May 28, 2025
b7cba1a
fix: revert temporary fix that shouldn't have been pushed
averissimo May 28, 2025
329f728
fix: use teal_report object instead of teal_data in signature
averissimo May 28, 2025
a66fa15
Merge remote-tracking branch 'origin/main' into teal_reportable
gogonzo Jun 2, 2025
a31fdaa
Remove unnecessary methods
gogonzo Jun 3, 2025
860edf1
Add "Code preparation" heading
gogonzo Jun 3, 2025
9047461
Merge branch 'main' into redesign@main
averissimo Jun 4, 2025
7c3b571
Merge remote-tracking branch 'origin/redesign@main' into teal_reportable
averissimo Jun 4, 2025
a7f76e9
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jun 5, 2025
33c0ff3
chore: add remotes
averissimo Jun 5, 2025
f01ad09
chore: bump deps versions
averissimo Jun 6, 2025
8b48ac0
tests: update test to new method of disabling reporter globaly
averissimo Jun 6, 2025
1516f8f
tests: fix previewer was inserted in teal_slices
averissimo Jun 6, 2025
8b37b72
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jun 6, 2025
d356591
Naming (#1542)
m7pr Jun 6, 2025
473b987
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jun 6, 2025
8d2477e
chore: linter errors
averissimo Jun 6, 2025
60d5707
docs: fix spelling
averissimo Jun 6, 2025
82fd605
chore: cleanup for CI
averissimo Jun 6, 2025
f4ac12f
chore: rcmdcheck with 0 erros and warnings
averissimo Jun 6, 2025
4f2e06a
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Jun 6, 2025
65e6e04
empty: trigger ci
averissimo Jun 6, 2025
93071a3
chore: fix docs ci
averissimo Jun 6, 2025
abb2307
Disable report when error (#1547)
gogonzo Jun 12, 2025
290cbb9
changing sections to h2 as h1 is dedicated to the title
gogonzo Jun 19, 2025
cf9c3b4
adding an attribute to start a new chunk for following (no .collapse_…
gogonzo Jun 19, 2025
52e71b1
Merge remote-tracking branch 'origin/main' into teal_reportable
gogonzo Jun 26, 2025
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
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ BugReports: https://github.com/insightsengineering/teal/issues
Depends:
R (>= 4.1),
shiny (>= 1.8.1),
teal.data (>= 0.7.0),
teal.data (>= 0.7.0.9002),
teal.slice (>= 0.6.0.9001)
Imports:
bsicons,
Expand All @@ -52,8 +52,8 @@ Imports:
rlang (>= 1.0.0),
shinyjs,
stats,
teal.code (>= 0.6.1),
teal.logger (>= 0.3.2.9001),
teal.code (>= 0.6.1.9002),
teal.reporter (>= 0.4.0.9004),
teal.widgets (>= 0.4.3.9001),
tools,
Expand All @@ -76,11 +76,11 @@ Suggests:
VignetteBuilder:
knitr,
rmarkdown
RdMacros:
lifecycle
Remotes:
insightsengineering/teal.code@teal_reportable,
insightsengineering/teal.data@teal_reportable,
insightsengineering/teal.logger@main,
insightsengineering/teal.reporter@main,
insightsengineering/teal.reporter@teal_reportable,
insightsengineering/teal.slice@main,
insightsengineering/teal.widgets@main
Config/Needs/verdepcheck: rstudio/shiny, insightsengineering/teal.data,
Expand All @@ -102,6 +102,7 @@ Roxygen: list(markdown = TRUE, packages = c("roxy.shinylive"))
RoxygenNote: 7.3.2
Collate:
'TealAppDriver.R'
'after.R'
'checkmate.R'
'dummy_functions.R'
'include_css_js.R'
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ S3method(ui_teal_module,teal_modules)
S3method(within,teal_data_module)
export(TealReportCard)
export(add_landing_modal)
export(after)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this is a really bad name that can mean anything. It feels very much async related. Please reassess the name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to let you know @pawelru - this is a function that edits/manipulates teal_data (now extended to teal_report class) after it was returned by module's server. It is applied on a module level.

So basically it is:

module() |>
    edit_data_returned_by_server()

Copy link
Contributor

@donyunardi donyunardi Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about modify_teal_module or edit_teal_module?
Then, we'll have .modify/edit_teal_module_ui and .modify/edit_teal_module_srv

EDIT: I saw the comment that this was previously called modify_reactive_output.

export(as.teal_slices)
export(as_tdata)
export(build_app_title)
export(disable_report)
export(example_module)
export(get_code_tdata)
export(get_metadata)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# teal 0.16.0.9009

### New features

* `init` and `srv_teal` have new `reporter` parameter, that allows to pre-define `teal.reporter::Reporter` object to be
used for storing the content of the report. You can also globally disable reporting by setting `reporter = NULL`
(and `disable = TRUE` in `ui_teal` for cases when `ui_teal` is used as shiny module).
* TODO: verify if we need to clone/deep_clone reporter in `srv_teal/init`.

# teal 0.16.0

### New features
Expand Down
91 changes: 91 additions & 0 deletions R/after.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#' Executes modifications to the result of a module
#'
#' Primarily used to modify the output object of module to change the containing
#' report.
#' @param x (`teal_data`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#' @param x (`teal_data`)
#' @param x (`teal_module`)

#' @param ui (`function(id, elem, ...)`) function to receive output (`shiny.tag`) from `x$ui`
#' @param server (`function(input, output, session, data, ...)`) function to receive output data from `x$server`
#' @param ... additional argument passed to `ui` and `server` by matching their formals names.
#' @return A `teal_report` object with the result of the server function.
#' @export
after <- function(x,
ui = function(id, elem) elem,
server = function(input, output, session, data) data,
...) {
Comment on lines +5 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since after is applied like below

<teal_module> |> after(
        server = function(data) {
          teal.reporter::teal_card(data) <- c(
            teal.reporter::teal_card(data),
            "# added content",
            "This content has been added through `after`"
          )
          data
        }
      )

I think

#' @param x (`teal_data`)

should be updated to

#' @param x (`teal_module`)

and

server = function(input, output, session, data) data

to

server = function(data) data

?

# todo: make a method for teal_app and remove teal_extend_server?
checkmate::assert_multi_class(x, "teal_module")
if (!is.function(ui) || !all(names(formals(ui)) %in% c("id", "elem"))) {
stop("ui should be a function of id and elem")
}
if (!is.function(server) || !all(names(formals(server)) %in% c("input", "output", "session", "data"))) {
stop("server should be a function of `input` and `output`, `session`, `data`")
}
Comment on lines +20 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are those checks even working if we pass server function without input, output and session?

<teal_module> |> after(
        server = function(data) {
          teal.reporter::teal_card(data) <- c(
            teal.reporter::teal_card(data),
            "# added content",
            "This content has been added through `after`"
          )
          data
        }
      )


additional_args <- list(...)
new_x <- x # because overwriting x$ui/server will cause infinite recursion
new_x$ui <- .after_ui(x$ui, ui, additional_args)
new_x$server <- .after_server(x$server, server, additional_args)
new_x
}

.after_ui <- function(x, y, additional_args) {
# add `_`-prefix to make sure objects are not masked in the wrapper functions
`_x` <- x # nolint: object_name.
`_y` <- y # nolint: object_name.
new_x <- function(id, ...) {
original_args <- as.list(environment())
if ("..." %in% names(formals(`_x`))) {
original_args <- c(original_args, list(...))
}
ns <- NS(id)
original_args$id <- ns("wrapped")
original_out <- do.call(`_x`, original_args, quote = TRUE)

wrapper_args <- c(
additional_args,
list(id = ns("wrapper"), elem = original_out)
)
do.call(`_y`, args = wrapper_args[names(formals(`_y`))])
}
formals(new_x) <- formals(x)
new_x
}

.after_server <- function(x, y, additional_args) {
# add `_`-prefix to make sure objects are not masked in the wrapper functions
`_x` <- x # nolint: object_name.
`_y` <- y # nolint: object_name.
new_x <- function(id, ...) {
original_args <- as.list(environment())
original_args$id <- "wrapped"
if ("..." %in% names(formals(`_x`))) {
original_args <- c(original_args, list(...))
}
moduleServer(id, function(input, output, session) {
original_out <- if (all(c("input", "output", "session") %in% names(formals(`_x`)))) {
original_args$module <- `_x`
do.call(shiny::callModule, args = original_args)
} else {
do.call(`_x`, original_args)
}
original_out_r <- reactive(
if (is.reactive(original_out)) {
original_out()
} else {
original_out
}
)
wrapper_args <- utils::modifyList(
additional_args,
list(id = "wrapper", input = input, output = output, session = session)
)
reactive({
req(original_out_r())
wrapper_args$data <- original_out()
do.call(`_y`, wrapper_args[names(formals(`_y`))], quote = TRUE)
})
})
}
formals(new_x) <- formals(x)
new_x
}
13 changes: 10 additions & 3 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#' a string specifying the `shiny` module id in cases it is used as a `shiny` module
#' rather than a standalone `shiny` app.
#' This parameter is no longer supported. Use [ui_teal()] and [srv_teal()] instead.
#' @param reporter (`Reporter`) object used to store report contents. Set to `NULL` to globally disable reporting.
#'
#' @return Named list containing server and UI functions.
#'
Expand Down Expand Up @@ -99,7 +100,8 @@ init <- function(data,
title = lifecycle::deprecated(),
header = lifecycle::deprecated(),
footer = lifecycle::deprecated(),
id = lifecycle::deprecated()) {
id = lifecycle::deprecated(),
reporter = teal.reporter::Reporter$new()) {
logger::log_debug("init initializing teal app with: data ('{ class(data) }').")

# argument checking (independent)
Expand Down Expand Up @@ -183,7 +185,6 @@ init <- function(data,
landing <- extract_module(modules, "teal_module_landing")
modules <- drop_module(modules, "teal_module_landing")


if (lifecycle::is_present(id)) {
lifecycle::deprecate_soft(
when = "0.16.0",
Expand Down Expand Up @@ -231,7 +232,13 @@ init <- function(data,
)
},
server = function(input, output, session) {
srv_teal(id = "teal", data = data, modules = modules, filter = deep_copy_filter(filter))
srv_teal(
id = "teal",
data = data,
modules = modules,
filter = deep_copy_filter(filter),
reporter = if (!is.null(reporter)) reporter$clone(deep = TRUE)
)
srv_session_info("teal-footer-session_info")
}
),
Expand Down
24 changes: 17 additions & 7 deletions R/module_init_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,31 @@ srv_init_data <- function(id, data) {
#' @keywords internal
.add_signature_to_data <- function(data) {
hashes <- .get_hashes_code(data)
data_teal_report <- teal.reporter::as.teal_report(data)
if (!inherits(data, "teal_report")) {
teal.reporter::teal_card(data_teal_report) <- c(
teal.reporter::teal_card(),
"## Code preparation",
teal.reporter::teal_card(data_teal_report)
)
}
tdata <- do.call(
teal.data::teal_data,
teal.reporter::teal_report,
c(
list(code = trimws(c(teal.code::get_code(data), hashes), which = "right")),
list(join_keys = teal.data::join_keys(data)),
list(
code = trimws(c(teal.code::get_code(data_teal_report), hashes), which = "right"),
join_keys = teal.data::join_keys(data_teal_report),
teal_card = teal.reporter::teal_card(data_teal_report)
),
sapply(
names(data),
names(data_teal_report),
teal.code::get_var,
object = data,
object = data_teal_report,
simplify = FALSE
)
)
)

tdata@verified <- data@verified
tdata@verified <- data_teal_report@verified
tdata
}

Expand Down
28 changes: 12 additions & 16 deletions R/module_nested_tabs.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ ui_teal_module.teal_module <- function(id, modules, depth = 0L) {
div(
id = id,
class = "teal_module",
ui_add_reporter(ns("add_reporter_wrapper")),
# uiOutput(ns("show_rcode_container")), # todo: same mechanism as for the reporter
uiOutput(ns("data_reactive"), inline = TRUE),
tagList(
if (depth >= 2L) tags$div(),
Expand Down Expand Up @@ -226,7 +228,7 @@ srv_teal_module <- function(id,
checkmate::assert_multi_class(modules, c("teal_modules", "teal_module"))
assert_reactive(datasets, null.ok = TRUE)
checkmate::assert_class(slices_global, ".slicesGlobal")
checkmate::assert_class(reporter, "Reporter")
checkmate::assert_class(reporter, "Reporter", null.ok = TRUE)
assert_reactive(data_load_status)
UseMethod("srv_teal_module", modules)
}
Expand Down Expand Up @@ -395,21 +397,15 @@ srv_teal_module.teal_module <- function(id,
})

# Call modules.
if (!inherits(modules, "teal_module_previewer")) {
obs_module <- .call_once_when(
!is.null(module_teal_data()),
ignoreNULL = TRUE,
handlerExpr = {
module_out(.call_teal_module(modules, datasets, module_teal_data, reporter))
}
)
} else {
# Report previewer must be initiated on app start for report cards to be included in bookmarks.
# When previewer is delayed, cards are bookmarked only if previewer has been initiated (visited).
module_out(.call_teal_module(modules, datasets, module_teal_data, reporter))
}
obs_module <- .call_once_when(
!is.null(module_teal_data()),
ignoreNULL = TRUE,
handlerExpr = {
module_out(.call_teal_module(modules, datasets, module_teal_data, reporter))
srv_add_reporter("add_reporter_wrapper", module_out, reporter)
}
)
})

module_out
})
}
Expand All @@ -420,7 +416,7 @@ srv_teal_module.teal_module <- function(id,

# collect arguments to run teal_module
args <- c(list(id = "module"), modules$server_args)
if (is_arg_used(modules$server, "reporter")) {
if (is_arg_used(modules$server, "reporter") && !is.null(reporter)) {
args <- c(args, list(reporter = reporter))
}

Expand Down
6 changes: 6 additions & 0 deletions R/module_snapshot_manager.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ srv_snapshot_manager <- function(id, slices_global) {
showModal(
modalDialog(
textInput(ns("snapshot_name"), "Name the snapshot", width = "100%", placeholder = "Meaningful, unique name"),
tags$script(
shiny::HTML(
sprintf("shinyjs.autoFocusModal('%s');", ns("snapshot_name")),
sprintf("shinyjs.enterToSubmit('%s', '%s');", ns("snapshot_name"), ns("snapshot_name_accept"))
)
),
footer = tagList(
actionButton(ns("snapshot_name_accept"), "Accept", icon = icon("far fa-thumbs-up")),
modalButton(label = "Cancel", icon = icon("far fa-thumbs-down"))
Expand Down
29 changes: 16 additions & 13 deletions R/module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ ui_teal <- function(id, modules) {
checkmate::assert_character(id, max.len = 1, any.missing = FALSE)
checkmate::assert_class(modules, "teal_modules")
ns <- NS(id)

modules <- append_reporter_module(modules)

modules <- drop_module(modules, "teal_previewer_module")
# show busy icon when `shiny` session is busy computing stuff
# based on https://stackoverflow.com/questions/17325521/r-shiny-display-loading-message-while-function-is-running/22475216#22475216 # nolint: line_length.
shiny_busy_message_panel <- conditionalPanel(
Expand Down Expand Up @@ -103,14 +101,14 @@ ui_teal <- function(id, modules) {

#' @rdname module_teal
#' @export
srv_teal <- function(id, data, modules, filter = teal_slices()) {
srv_teal <- function(id, data, modules, filter = teal_slices(), reporter = teal.reporter::Reporter$new()) {
checkmate::assert_character(id, max.len = 1, any.missing = FALSE)
checkmate::assert_multi_class(data, c("teal_data", "teal_data_module", "reactive"))
checkmate::assert_class(modules, "teal_modules")
checkmate::assert_class(filter, "teal_slices")

modules <- append_reporter_module(modules)

if (!is.null(reporter)) {
modules <- append_reporter_module(modules)
}
moduleServer(id, function(input, output, session) {
logger::log_debug("srv_teal initializing.")

Expand Down Expand Up @@ -148,7 +146,6 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {
srv_check_module_datanames("datanames_warning", data_handled, modules)

data_validated <- .trigger_on_success(data_handled)

data_signatured <- reactive({
req(inherits(data_validated(), "teal_data"))
is_filter_ok <- check_filter_datanames(filter, names(data_validated()))
Expand Down Expand Up @@ -181,8 +178,6 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {
})
}



if (inherits(data, "teal_data_module")) {
setBookmarkExclude(c("teal_modules-active_tab"))
bslib::nav_insert(
Expand Down Expand Up @@ -215,18 +210,26 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {
)
}

reporter <- teal.reporter::Reporter$new()$set_id(attr(filter, "app_id"))
module_labels <- unlist(module_labels(modules), use.names = FALSE)
module_labels <- unlist(module_labels(drop_module(modules, "teal_module_previewer")), use.names = FALSE)

slices_global <- methods::new(".slicesGlobal", filter, module_labels)
modules_output <- srv_teal_module(
id = "teal_modules",
data = data_signatured,
datasets = datasets_rv,
modules = modules,
modules = drop_module(modules, "teal_module_previewer"),
slices_global = slices_global,
data_load_status = data_load_status,
reporter = reporter
)

insert_reporter_previewer_tab(
session = session,
modules = modules,
modules_output = modules_output,
reporter = reporter,
app_id = attr(filter, "app_id")
)
mapping_table <- srv_filter_manager_panel("filter_manager_panel", slices_global = slices_global)
snapshots <- srv_snapshot_manager_panel("snapshot_manager_panel", slices_global = slices_global)
srv_bookmark_panel("bookmark_manager", modules)
Expand Down
2 changes: 1 addition & 1 deletion R/modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ append_module <- function(modules, module) {
#' @keywords internal
#' @noRd
append_reporter_module <- function(modules) {
if (is_arg_used(modules, "reporter") && length(extract_module(modules, "teal_module_previewer")) == 0) {
if (length(extract_module(modules, "teal_module_previewer")) == 0) {
modules <- append_module(
modules,
reporter_previewer_module(server_args = list(previewer_buttons = c("download", "reset")))
Expand Down
Loading
Loading