Skip to content

Conversation

llrs-roche
Copy link
Contributor

@llrs-roche llrs-roche commented Sep 12, 2025

Pull Request

Fixes #1591

Blocked: Waiting for #1592 to be merged

Update the vignette to explain how teal.reporter can be used to generate the report on modules.

There might be room for improvement on the vignette as this is my first module using this new features.
Specially this section of code doesn't seem self explanatory:

 teal.reporter::teal_card(obj) <-
            c(
              teal.reporter::teal_card("# Module with reporting"),
              teal.reporter::teal_card(obj),
              teal.reporter::teal_card("## Module's code")
            )

It is an object of class teal_report (of a single module!) being modified by the function teal_card to add teal_cards. But I might have got this wrong.

Another thing I'm not confident is on having to use module()[[input$dataname]] for the renderPrint. After having to add a line to print the table selected for the report.

I removed lot's of apps that showed intermediate work, as I think now it can be done in two steps:

  1. Adding a card
  2. Returning it to be used by teal

Awesome work that went into this!
In general, it felt very easy to set it up once I got around the teal_reporter and teal_card classes seeing other modules on TMG. But let me know if I missed a clearer description.

@llrs-roche llrs-roche marked this pull request as ready for review September 15, 2025 10:27
Copy link
Contributor

github-actions bot commented Sep 15, 2025

Unit Tests Summary

  1 files   26 suites   2m 15s ⏱️
262 tests 207 ✅ 55 💤 0 ❌
448 runs  393 ✅ 55 💤 0 ❌

Results for commit 71581fc.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Sep 15, 2025

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
module_teal 💔 $108.71$ $+1.98$ $0$ $0$ $0$ $0$

Results for commit 559cb36

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Sep 15, 2025

badge

Code Coverage Summary

Filename                          Stmts    Miss  Cover    Missing
------------------------------  -------  ------  -------  ---------------------------------------------------------------------------------------------------------------------------------------------
R/after.R                            63      63  0.00%    16-90
R/checkmate.R                        24       0  100.00%
R/dummy_functions.R                  67      11  83.58%   44, 46, 88-96
R/include_css_js.R                   11      11  0.00%    12-37
R/init.R                            152     106  30.26%   139-160, 189-197, 207-236, 239-246, 253-262, 265-274, 277-286, 290-300, 302
R/landing_popup_module.R             34      34  0.00%    22-57
R/module_bookmark_manager.R         153     122  20.26%   47-58, 78-133, 138-139, 151, 198, 233-310
R/module_data_summary.R             177      10  94.35%   25-26, 40, 50, 205, 236-240
R/module_filter_data.R               64       2  96.88%   22-23
R/module_filter_manager.R           229      56  75.55%   56-61, 72-81, 89-94, 107-111, 116-117, 290-313, 339, 366, 378, 385-386
R/module_init_data.R                 84       6  92.86%   38-43
R/module_nested_tabs.R              363     207  42.98%   68-98, 125, 140-322, 354, 472-475, 479-482, 486-489, 533, 586-589
R/module_session_info.R              18       7  61.11%   35-41
R/module_snapshot_manager.R         271     200  26.20%   89-94, 103-112, 120-144, 163-164, 181-210, 214-229, 231-238, 245-275, 279, 283-287, 289-295, 298-311, 314-322, 352-366, 369-380, 383-397, 410
R/module_teal_data.R                149      76  48.99%   43-149
R/module_teal_lockfile.R            131      69  47.33%   33-37, 45-57, 60-62, 76, 86-88, 92-96, 100-102, 110-119, 122, 124, 126-127, 142-146, 161-162, 177-186, 196-201
R/module_teal_with_splash.R          33      33  0.00%    24-61
R/module_teal.R                     199      83  58.29%   49-115, 132, 143-144, 184, 202-218, 220
R/module_transform_data.R           116       7  93.97%   20, 46, 130-134
R/modules.R                         291      53  81.79%   173-177, 232-235, 359-379, 387, 393, 570-576, 589-597, 612-627, 660, 673
R/reporter_previewer_module.R        41      41  0.00%    22-85
R/show_rcode_modal.R                 31      31  0.00%    17-49
R/tdata.R                            14      14  0.00%    19-61
R/teal_data_module-eval_code.R       23       0  100.00%
R/teal_data_module-within.R           7       0  100.00%
R/teal_data_module.R                 20       0  100.00%
R/teal_data_utils.R                  40       0  100.00%
R/teal_modifiers.R                   71      71  0.00%    26-214
R/teal_reporter.R                    82      14  82.93%   60, 77-78, 81, 98-103, 108, 124, 126, 168-172
R/teal_slices-store.R                29       0  100.00%
R/teal_slices.R                      63       0  100.00%
R/teal_transform_module.R            45       0  100.00%
R/TealAppDriver.R                   377     377  0.00%    57-756
R/utils.R                           291      60  79.38%   402-451, 499-510, 539-548
R/validate_inputs.R                  32       0  100.00%
R/validations.R                      58      37  36.21%   114-392
R/zzz.R                              18      14  22.22%   4-21
TOTAL                              3871    1815  53.11%

Diff against main

Filename      Stmts    Miss  Cover
----------  -------  ------  --------
TOTAL             0       0  +100.00%

Results for commit: 26f05f1

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@m7pr
Copy link
Contributor

m7pr commented Sep 16, 2025

@llrs-roche @averissimo I posted the same question in teal.reporter PR insightsengineering/teal.reporter#407

Should we extend teal_report vignette or vignettes/adding-support-for-reporting.Rmd in teal with an information on how to use after function, and how to predefine the reporter content and template?

We can reuse the code from this app insightsengineering/teal.reporter#388

@m7pr
Copy link
Contributor

m7pr commented Sep 16, 2025

@llrs-roche @averissimo I also think that with this PR we should:

  • add examples to after function
  • have a conversation on whether we should rename after function to something else, like edit_server, edit_server_data

@llrs-roche
Copy link
Contributor Author

@m7pr We can expand the scope of this PR to include the after function. But I don't think this is wise, after doesn't have any test and while the documentation says that it is "to change the containing report." I don't think it has protections to avoid other changes.

But I see the liberty this function gives to modify what is done with something of a module without adding a decorator.

I could simply change the output of the report by just subsetting an object:

library("teal.reporter")
app <- init(
  data = teal_data(IRIS = iris, MTCARS = mtcars),
  modules = example_module() |> after(server = function(input, output, session, data) {
    teal_card(data) <- c(teal_card(data), teal.reporter::teal_card("Modification"))
    within(data, object[, 1:2])
    })
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

The web/module looks the same but the report has an extra output with just the first two columns.

@m7pr
Copy link
Contributor

m7pr commented Sep 16, 2025

@llrs-roche also an example that covers point 1 and 2 from this example
image

and when it comes to after, a good example is also to show disable_reporter.
We will also have disable_src (disable show R code), really soon with #1592

@llrs-roche
Copy link
Contributor Author

llrs-roche commented Sep 16, 2025

I am okay with showing how to use after, disable_reporter and disable_src. They are part of teal and might be used with custom-made modules. I guess this is a good place to show them working together. I guess one can use reporte in a module but might not be interested on showing the R code. Or the opposite: have only show the R code but not the report.

The current version of the vignette focus only on what is needed to add reporter to a custom module not on all the bells and whistles that a reporter has. Features like modifying the reporter template or have an app with a pre-loaded card might be better shown on teal.reporter.

@m7pr
Copy link
Contributor

m7pr commented Sep 16, 2025

I think the pre-defining reporter and it's template is a part of teal, since reporter is a parameter in init() and you can disable globally the reporter only with init(reporter = NULL) and disable reporter locally with teal functions (disable_reporter or after).

Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com>
Signed-off-by: Lluís Revilla <185338939+llrs-roche@users.noreply.github.com>
Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com>
Signed-off-by: Lluís Revilla <185338939+llrs-roche@users.noreply.github.com>
Copy link
Contributor Author

@llrs-roche llrs-roche left a comment

Choose a reason for hiding this comment

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

Thanks for the detailed review

) |>
modify_header(tags$h2("Example teal app with reporter"))
reporter = reporter
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com>
Signed-off-by: Lluís Revilla <185338939+llrs-roche@users.noreply.github.com>
}
```
`teal.reporter` supports the addition of tables, charts, and more.
For more information, explore the API of `teal.reporter::ReportCard` to learn about the supported content types.
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 teal.reporter::ReportCard got deprecated. I think we should link to teal.reporter::teal_report and it's teal_report-class vignette

```

The key step is to return a `teal_report` object containing everything.
This informs `teal` that the module provides a `reporter`, and teal will add a button `+ Add to Report` to add the modules' code to the report.
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
This informs `teal` that the module provides a `reporter`, and teal will add a button `+ Add to Report` to add the modules' code to the report.
This informs `teal` that the module provides a `reporter`, and teal will add a button `+ Add to Report` to add the modules' contents to the report.

knitr::include_url(url, height = "800px")
```

The key step is to return a `teal_report` object containing everything.
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
The key step is to return a `teal_report` object containing everything.
The key step is to return a reactive `teal_report` object containing everything.

Comment on lines 124 to 125
req(rtd <- report(), input$dataname)
within(rtd, table, table = as.name(input$dataname))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we come up with a better variable name than rtd and dr (couple lines below)?
Having a descriptive variable may help learning process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to teal_data on both cases to make it easier to remember and still be truthfhul but not sure if I should change also report to report_r (for reactive) and use report instead of teal_data.

However, there is no visible change in how the module operates and appears and the user cannot add content to the report from this module.
That requires inserting UI and server elements of the `teal.reporter` module into the module body.
The output hasn't changed (yet).
We need one last step so that the module can be reported.
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
We need one last step so that the module can be reported.
The final step is to have the server return the reporter object, enabling the module to be reported.

I thought it would be good to mention what was the last/final step before we got to the next section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

`teal` exports the `TealReportCard` class, which extends the `teal.reporter::ReportCard` class and provides several convenient methods to facilitate working with `teal` features like the filter panel or source code.
For more details, refer to the documentation of `TealReportCard`.
If a module has the reporter functionality the teal app developer can disable it with `disable_report()`.
To remove reporting from the whole application, set `reporter = NULL` in ìnit()`.
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
To remove reporting from the whole application, set `reporter = NULL` in ìnit()`.
To remove reporting from the whole application, set `reporter = NULL` in init()`.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's an example for disable_report(), do we need example for init(reporter=NULL)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure an example is needed as it would be even less interactive than what we have. But maybe we can add a sentence and a screenshot?

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 would help

Comment on lines 325 to 327
One can set a template of the report.
Then each card added to the report will contain template's content by default.
We can also add cards to the report before the application is started.
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
One can set a template of the report.
Then each card added to the report will contain template's content by default.
We can also add cards to the report before the application is started.
A template can be set for the report, ensuring that each card added to the report contains the template's default content. Additionally, cards can be added to the report before the application starts.

Just a suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the working but I slightly modified the sentence. Let me know if it flows well.

)
)
Once the reporter is created we can use in the teal application.
We can also extend a report for a specific module using `after()`:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we explain more on after() usage? So far, we only have this one liner and then the example code below. Maybe highlight a little bit on when user would want to use this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add more explanation about why and how to work with it.
Although it is a bit unclear to me, as the function doesn't have examples or tests/testthat.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opened a PR for after: #1597

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with Marcin that it is better to work on that in a different branch/PR as I think the function needs more work. See this draft and comments: #1597

We need one last step so that the module can be reported.

### Insert `teal.reporter` module
### Return the reporter object
Copy link
Contributor

Choose a reason for hiding this comment

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

This should also be described in creating-custom-modules.Rmd vignette.

Maybe just return the object there and reference here for more information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I'll modify that vignette too

@m7pr
Copy link
Contributor

m7pr commented Sep 17, 2025

hey, when it comes to extending after function with examples and potentially renaming it something else. I think we can do it on a separate issue/PR.

Copy link
Contributor Author

@llrs-roche llrs-roche left a comment

Choose a reason for hiding this comment

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

Thanks for the feedback

Comment on lines 124 to 125
req(rtd <- report(), input$dataname)
within(rtd, table, table = as.name(input$dataname))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to teal_data on both cases to make it easier to remember and still be truthfhul but not sure if I should change also report to report_r (for reactive) and use report instead of teal_data.

`teal` exports the `TealReportCard` class, which extends the `teal.reporter::ReportCard` class and provides several convenient methods to facilitate working with `teal` features like the filter panel or source code.
For more details, refer to the documentation of `TealReportCard`.
If a module has the reporter functionality the teal app developer can disable it with `disable_report()`.
To remove reporting from the whole application, set `reporter = NULL` in ìnit()`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure an example is needed as it would be even less interactive than what we have. But maybe we can add a sentence and a screenshot?

Comment on lines 325 to 327
One can set a template of the report.
Then each card added to the report will contain template's content by default.
We can also add cards to the report before the application is started.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the working but I slightly modified the sentence. Let me know if it flows well.

We need one last step so that the module can be reported.

### Insert `teal.reporter` module
### Return the reporter object
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I'll modify that vignette too

However, there is no visible change in how the module operates and appears and the user cannot add content to the report from this module.
That requires inserting UI and server elements of the `teal.reporter` module into the module body.
The output hasn't changed (yet).
We need one last step so that the module can be reported.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

)
)
Once the reporter is created we can use in the teal application.
We can also extend a report for a specific module using `after()`:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add more explanation about why and how to work with it.
Although it is a bit unclear to me, as the function doesn't have examples or tests/testthat.

# Pull Request

Part of #1591 
Companion of #1593 

Requires #1592 to be
merged on main before it can be merged to main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Documentation]: Update adding-support-for-reporting.Rmd vignette in teal to use the new approach
4 participants