Skip to content

📑 Reporter Refactor: Adds support for new teal_report and teal_card class#1541

Merged
averissimo merged 157 commits into
mainfrom
teal_reportable
Sep 4, 2025
Merged

📑 Reporter Refactor: Adds support for new teal_report and teal_card class#1541
averissimo merged 157 commits into
mainfrom
teal_reportable

Conversation

@averissimo

@averissimo averissimo commented Jun 3, 2025

Copy link
Copy Markdown
Contributor

Pull Request

Built on top of:

Companion PRs:

Changes description

  • Adds a "Add to reporter" when a teal_report object is returned from the module
  • Changes modify_reactive_output() to after()

Sample app

# Make sure the required branches are checked-out
# - teal_reporter (all 4: teal, teal.reporter, teal.code, teal.data)
# - redesign@main (teal, teal.reporter, teal.code)
pkgload::load_all("../teal.code")
pkgload::load_all("../teal.data")
pkgload::load_all("../teal.reporter")
pkgload::load_all("../teal")

example_extended <- function(label = "example teal module",
                                 datanames = "all",
                                 transformators = list(),
                                 decorators = list()) {
  checkmate::assert_string(label)
  checkmate::assert_list(decorators, "teal_transform_module")
  
  mod <- example_module(label, datanames, transformators, decorators)
  
  module(
    label,
    server = function(id, data, decorators) {
      moduleServer(id, function(input, output, session) {
        result <- mod$server("example", data, decorators)
        
        reactive({
          data <- result()
          report(data) <- c(doc("## Code"), report(data), "## Table", data$object)  
          data
        })
        
      })
    },
    ui = function(id, decorators) mod$ui(shiny::NS(id, "example"), decorators),
    ui_args = mod$ui_args,
    server_args = mod$server_args,
    datanames = mod$datanames,
    transformators = mod$transformators
  )
}

example_old_reporter <- function(label = "example teal module",
                                 datanames = "all",
                                 transformators = list(),
                                 decorators = list()) {
  checkmate::assert_string(label)
  checkmate::assert_list(decorators, "teal_transform_module")
  
  ans <- module(
    label,
    server = function(id, data, decorators, reporter, filter_panel_api) {
      moduleServer(id, function(input, output, session) {
        result <- example_module()$server("example", data, decorators)
        
        teal.widgets::verbatim_popup_srv(
          id = "rcode",
          verbatim_content = reactive(teal.code::get_code(req(result()))),
          title = "Example Code"
        )
        
        if (inherits(reporter, "Reporter")) {
          card_fun <- function(comment, label) {
            card <- teal::report_card_template(
              title = "Example plot",
              label = label,
              with_filter = FALSE,
              filter_panel_api = filter_panel_api
            )
            card$append_rcode(get_code(result()))
            card$append_text("Table", "header3")
            card$append_table(result()[["object"]])
            card
          }
          teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)
        }
      })
    },
    ui = function(id, decorators) {
      ns <- NS(id)
      teal.widgets::standard_layout(
        output = verbatimTextOutput(ns("example-text")),
        encoding = tags$div(
          teal.reporter::simple_reporter_ui(ns("simple_reporter")),
          selectInput(ns("example-dataname"), "Choose a dataset", choices = NULL),
          ui_transform_teal_data(ns("example-decorate"), transformators = decorators),
          teal.widgets::verbatim_popup_ui(ns("rcode"), "Show R code")
        )
      )
    },
    ui_args = list(decorators = decorators),
    server_args = list(decorators = decorators),
    datanames = datanames,
    transformators = transformators
  )
  attr(ans, "teal_bookmarkable") <- TRUE
  ans
}


teal::init(
  data = within(teal_data(), {iris <- iris}),
  modules = modules(
    example_extended(label = "🆕 Module (extended)"),
    example_old_reporter(label = "⏲️ Old reporter"),
    example_module(label = "🆕 Module (from {teal})"),
    example_module(label = "❌️ No reporter") |> disable_report()
  )
) |> shiny::runApp()

vedhav and others added 30 commits September 17, 2024 15:43
# Conflicts:
#	R/module_nested_tabs.R
#	R/module_teal.R
#	R/module_transform_data.R
# Conflicts:
#	R/module_nested_tabs.R
# Conflicts:
#	DESCRIPTION
#	R/module_data_summary.R
#	R/module_nested_tabs.R
#	R/module_teal.R
#	R/module_transform_data.R
# Conflicts:
#	R/module_teal.R
Hey @vedhav @gogonzo just letting you know that I am merging `main` into
`test@bslib@main` branch, so that on other repositories, like `tmg`, we
can install `teal` from this branch and also we can satisfy condition
for `teal` to be `>= 0.16.0`.


https://github.com/insightsengineering/teal.modules.general/blob/report_redesign_poc%40main/DESCRIPTION#L83

https://github.com/insightsengineering/teal.modules.general/blob/report_redesign_poc%40main/DESCRIPTION#L30

---------

Co-authored-by: Dony Unardi <donyunardi@gmail.com>
Co-authored-by: insights-engineering-bot <68416928+insights-engineering-bot@users.noreply.github.com>
Comment thread R/after.R
Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com>
Signed-off-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
Comment thread R/teal_reporter.R
Comment thread R/teal_reporter.R

@m7pr m7pr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey, I fixed tests, but I left 2 comments.
We also postponed one TODO and made an issue for that to handle at some point:
#1588

Comment thread DESCRIPTION
Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com>

@m7pr m7pr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great work on this. The next follow-up is created in this issue #1588

averissimo added a commit to insightsengineering/teal.reporter that referenced this pull request Sep 4, 2025
…orter UI (#331)

# Pull Request

Fixes:

- insightsengineering/teal#1526

Built on top of:

- #307
    - _(#307 will be closed once this PR is stable)_

### Companion PRs:

- insightsengineering/teal#1541
- insightsengineering/teal.code#255
- insightsengineering/teal.data#370
- #331
- insightsengineering/teal.modules.general#884
- insightsengineering/teal.modules.clinical#1392

### Changes description

- Adds new object called `teal_report` that extends `teal_data`
- The card/report for a module is built automatically with `eval_code()`
and `eval_code(cache = TRUE)`
        - (adding code and print objects respectively)
    - Report slot can be manipulated with `report(<teal_report>)`
- Rename of `report_document` to `doc`/`document`/`page` (final name
TBD)

---------

Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com>
Signed-off-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
Co-authored-by: m7pr <marcin.kosinski.mk1@roche.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Dawid Kaledkowski <dawid.kaledkowski@gmail.com>
Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com>
Co-authored-by: vedhav <vedhaviyash4@gmail.com>
Co-authored-by: Lluís Revilla <185338939+llrs-roche@users.noreply.github.com>
Co-authored-by: Pawel Rucki <12943682+pawelru@users.noreply.github.com>
@averissimo
averissimo enabled auto-merge (squash) September 4, 2025 12:53
@averissimo
averissimo disabled auto-merge September 4, 2025 12:57
@averissimo
averissimo merged commit aa610ad into main Sep 4, 2025
29 checks passed
@averissimo
averissimo deleted the teal_reportable branch September 4, 2025 13:15
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Question]: How to return report to teal?

8 participants