Skip to content

Vignette covering changes of teal.reporter refactor #1529

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

Closed
wants to merge 4 commits into from

Conversation

m7pr
Copy link
Contributor

@m7pr m7pr commented May 11, 2025

This is a separate PR, so we don't pollute the original feature PR with a lot of new comments.

@m7pr m7pr added the core label May 11, 2025
Comment on lines +26 to +36
* Address limited customization capabilities of the previous `ReportCard` system, which was tightly integrated with `teal` module programming, making user modifications difficult.
* Resolve reproducibility challenges associated with the existing `teal.reporter` (see [teal.reporter issue #280](https://github.com/insightsengineering/teal.reporter/issues/280)).
* Incorporate solutions for enabling and disabling reporter functions globally and for single modules.
* Allow to customize report cards without modifying the `teal` module programming, thus enabling users to create their own report cards (and edit existing ones).
* Ensure that the new reporting system is lightweight and does not consume excessive disk space, especially for bookmarking purposes.
* Maintain or improve existing functionalities, including the ability to generate fully reproducible reports.
* Provide a more flexible and scalable design that can adapt to future needs (Editor module can be extended for new R classes).
* Export Editor functionality to allow users to edit report cards directly in the UI.
* Introduce a new feature to disable the reporter functionality for one or multiple `teal` modules.
* Improve the user experience by providing a more intuitive interface for report generation and customization (changes in Reporter Previewer UI).
* Ensure that the new system is compatible with existing `teal` modules and does not break any existing functionality.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe somehow simplify this list of changes?
Can be used also to create NEWS.md entries

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems sensible, maybe changing to a feature list

1 example:

Ensure that the new reporting system is lightweight and does not consume excessive disk space, especially for bookmarking purposes.

to

Lightweight reporter system that reduces disk space usage (in particular with bookmarking)

Comment on lines +57 to +63
* **Technical Flow**:
1. **Adding a `ReportDocument`**: When the `Add to Reporter` button (from `teal::add_document_button_srv`) is clicked within a `teal` module, a `ReportDocument` is created and added to the `Reporter`'s list of cards.
2. **Previewing a Report**: Opening the "Report Preview(er)" tab triggers `reporter_previewer_srv`. This server function converts the `ReportDocument` elements into HTML for display using `toHTML`.
3. **Downloading a Report**: Clicking "Download Report" in the previewer executes `report_render_and_compress`. This function uses the `Renderer` to generate an `.Rmd` file from the `ReportDocument` objects. The output is a `.zip` file containing the `.Rmd` report and a JSON file (for restoring the report).
4. **Loading a Report**: Clicking "Load Report" clears the current report and restores it from the JSON file contained within an uploaded `.zip` archive.
5. **Editing a `ReportDocument`**: Users can click an "Edit" button associated with a `ReportDocument` card in the previewer to modify its text elements. Custom edit functionalities can be specified for different content classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need to explain the technical flow at all? Maybe for module developers this is helpful?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe as a standalone section or on a different user-facing vignette?

Comment on lines +64 to +67
* **UI Differences**:
* The only module-specific button for reporting is now "Add Card to Report".
* Global "Load Report", "Reset Report", and "Download Report" buttons are available in the Report Previewer.
* The download report encoding panel has been removed from the Report Previewer. It is now accessible via the "Download Report" button, which opens a modal dialog for encoding selection. This change was made to simplify the UI and reduce clutter.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we include print-screens of BEFORE and AFTER states?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good for the vignette, but it would need some maintenance over time.

Hopefully, there are no more big UI refactors

* Ensure that the new reporting system is lightweight and does not consume excessive disk space, especially for bookmarking purposes.
* Maintain or improve existing functionalities, including the ability to generate fully reproducible reports.
* Provide a more flexible and scalable design that can adapt to future needs (Editor module can be extended for new R classes).
* Export Editor functionality to allow users to edit report cards directly in the UI.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need a separate vignette for the Editor? Where we explain how to create your own editor_ui and editor_srv for custom classes?

* Address limited customization capabilities of the previous `ReportCard` system, which was tightly integrated with `teal` module programming, making user modifications difficult.
* Resolve reproducibility challenges associated with the existing `teal.reporter` (see [teal.reporter issue #280](https://github.com/insightsengineering/teal.reporter/issues/280)).
* Incorporate solutions for enabling and disabling reporter functions globally and for single modules.
* Allow to customize report cards without modifying the `teal` module programming, thus enabling users to create their own report cards (and edit existing ones).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this point to a separate vignette for modify_reactive_output?

* **Reduced storage size**: Being an S3 list, it avoids the overhead of storing methods and parent class environments associated with R6 objects, leading to smaller disk space usage, especially beneficial for bookmarking.
* **Flexible modifications**: `ReportDocument` supports easier reordering, subsetting, and editing of report content, both at the module development level and by the end-user in the Reporter Previewer tab.
* **Creation**: The primary function for creating a `ReportDocument` is `report_document()`. It can store various elements like characters (for text/markdown), data frames, plots, and code blocks.
* **Manipulation**: Standard list operations can be used. Additionally, `c.ReportDocument` and `[.ReportDocument` methods are provided. For robust editing, `edit_report_document()` allows modification and appending while preserving the `ReportDocument` class.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still unsure if we should keep edit_report_document. I have a feeling it's not needed anymore

Copy link
Contributor

Choose a reason for hiding this comment

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

That would keep the API a bit tighter, is it possible to completely replace the functions in edit_report_document?

Or does it need something like c(report_doc[1:2], "## Table 2", "yada", report_doc[3])

This sounds doable as our target audience with this feature are more experienced developers

A significant focus of the refactor was to enhance reproducibility and the clarity of code presented in reports.

* **Reproducibility**: The new design with `ReportDocument` and the refactored download/upload process aims to ensure that reports are fully reproducible.
* **Code Display**: Enhancements to `teal.code::eval_code` and `teal.code::get_code` now support code labelling, improving how R code is captured and displayed in the generated reports.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might not be true if we ever come up with a teal_data() + reporting integration and we abandon this code labelling.

```

* **Modifying Module Output for Reports**:
* The introduction of `modify_reactive_output()` allows developers to programmatically alter or disable report cards generated by modules. This provides fine-grained control over what is reported. Further documentation and a dedicated vignette for `modify_report_output()` are planned: TODO.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need a separate vignette for modify_report_output()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a bit covered at the end of the document

# card$append_table(my_summary_table)
# card$append_src(code_string)

# New way
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe point to PR in teal.modules.general?

Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com>
Comment on lines +238 to +239

6. **Return report_card as reactive in server**:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
6. **Return report_card as reactive in server**:
5. **Return report_card as reactive in server**:

```
* This allows to apply the `modify_reactive_output()` function to the report card, enabling further customization and control over what is included in the final report.

7. **No Need for `teal.reporter::simple_reporter_ui` and `teal.reporter::simple_reporter_srv`**:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
7. **No Need for `teal.reporter::simple_reporter_ui` and `teal.reporter::simple_reporter_srv`**:
6. **No Need for `teal.reporter::simple_reporter_ui` and `teal.reporter::simple_reporter_srv`**:



6. **Return report_card as reactive in server**:
* The `ReportDocument` should be returned as a reactive object in the server function of the module, wrapped in a names list under `report_card` name.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
* The `ReportDocument` should be returned as a reactive object in the server function of the module, wrapped in a names list under `report_card` name.
* The `ReportDocument` should be returned as a reactive object in the server function of the module, wrapped in a named list under `report_card` name.

teal.reporter::code_chunk(code_string)
)
})
return(list(report_card = report_card))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New name for report_card, or no name?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the no name approach, maybe even accepting reactives (as well as list of reactives).. It might make the transition to teal_data easier.

@averissimo averissimo self-assigned this May 12, 2025
@averissimo
Copy link
Contributor

This document mixes the transition with the previous reporter and new features.

Would it make sense to make the document more general and keep notes after each section title on the differences? This way we can remove those afterwards and the document would still be up-to-date?

@m7pr I think this goes on what you said in the meeting about this document be split in multiple

(I'm working through the vignette itself, just wanted to discuss this while as this thought is hovering in every section)

@m7pr
Copy link
Contributor Author

m7pr commented May 13, 2025

This document mixes the transition with the previous reporter and new features.

Yes @averissimo , but we also need some kind of a tutorial on how to migrate between old and new classes.

Would it make sense to make the document more general and keep notes after each section title on the differences? This way we can remove those afterwards and the document would still be up-to-date?

This would be great if you could help with that. Appreciate!

Copy link
Contributor

@averissimo averissimo left a comment

Choose a reason for hiding this comment

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

Here are some comments. Great work with the vignette.

It made looking at the PR easier for me!


This document outlines a significant refactor of `teal.reporter` and accompanying enhancements in the `teal` framework for improved reporting functionalities.

The primary goals of enhanced reporting were to:`
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 primary goals of enhanced reporting were to:`
The primary goals of enhanced reporting were to:

* Maintain or improve existing functionalities, including the ability to generate fully reproducible reports.
* Provide a more flexible and scalable design that can adapt to future needs (Editor module can be extended for new R classes).
* Export Editor functionality to allow users to edit report cards directly in the UI.
* Introduce a new feature to disable the reporter functionality for one or multiple `teal` modules.
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this the same as line 28?

  • Incorporate solutions for enabling and disabling reporter functions globally and for single modules.

Comment on lines +26 to +36
* Address limited customization capabilities of the previous `ReportCard` system, which was tightly integrated with `teal` module programming, making user modifications difficult.
* Resolve reproducibility challenges associated with the existing `teal.reporter` (see [teal.reporter issue #280](https://github.com/insightsengineering/teal.reporter/issues/280)).
* Incorporate solutions for enabling and disabling reporter functions globally and for single modules.
* Allow to customize report cards without modifying the `teal` module programming, thus enabling users to create their own report cards (and edit existing ones).
* Ensure that the new reporting system is lightweight and does not consume excessive disk space, especially for bookmarking purposes.
* Maintain or improve existing functionalities, including the ability to generate fully reproducible reports.
* Provide a more flexible and scalable design that can adapt to future needs (Editor module can be extended for new R classes).
* Export Editor functionality to allow users to edit report cards directly in the UI.
* Introduce a new feature to disable the reporter functionality for one or multiple `teal` modules.
* Improve the user experience by providing a more intuitive interface for report generation and customization (changes in Reporter Previewer UI).
* Ensure that the new system is compatible with existing `teal` modules and does not break any existing functionality.
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems sensible, maybe changing to a feature list

1 example:

Ensure that the new reporting system is lightweight and does not consume excessive disk space, especially for bookmarking purposes.

to

Lightweight reporter system that reduces disk space usage (in particular with bookmarking)


* **Motivation**: The `ReportCard` system faced limitations in customization, reproducibility, and storage efficiency. The new `ReportDocument` aims to overcome these by providing a simpler, more flexible, and lightweight approach to report generation.

* **`ReportDocument`**:
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
* **`ReportDocument`**:
* **`ReportDocument`** class:

* **Motivation**: The `ReportCard` system faced limitations in customization, reproducibility, and storage efficiency. The new `ReportDocument` aims to overcome these by providing a simpler, more flexible, and lightweight approach to report generation.

* **`ReportDocument`**:
* **Advantages**:
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 1 and 3 are debatable, for instance the "Flexible modifications" are new features that could've been done in R6.

A simple title change might better reflect the whole section

Suggested change
* **Advantages**:
* **Advantages** & **New features**:

* **Reduced storage size**: Being an S3 list, it avoids the overhead of storing methods and parent class environments associated with R6 objects, leading to smaller disk space usage, especially beneficial for bookmarking.
* **Flexible modifications**: `ReportDocument` supports easier reordering, subsetting, and editing of report content, both at the module development level and by the end-user in the Reporter Previewer tab.
* **Creation**: The primary function for creating a `ReportDocument` is `report_document()`. It can store various elements like characters (for text/markdown), data frames, plots, and code blocks.
* **Manipulation**: Standard list operations can be used. Additionally, `c.ReportDocument` and `[.ReportDocument` methods are provided. For robust editing, `edit_report_document()` allows modification and appending while preserving the `ReportDocument` class.
Copy link
Contributor

Choose a reason for hiding this comment

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

That would keep the API a bit tighter, is it possible to completely replace the functions in edit_report_document?

Or does it need something like c(report_doc[1:2], "## Table 2", "yada", report_doc[3])

This sounds doable as our target audience with this feature are more experienced developers

Comment on lines +57 to +63
* **Technical Flow**:
1. **Adding a `ReportDocument`**: When the `Add to Reporter` button (from `teal::add_document_button_srv`) is clicked within a `teal` module, a `ReportDocument` is created and added to the `Reporter`'s list of cards.
2. **Previewing a Report**: Opening the "Report Preview(er)" tab triggers `reporter_previewer_srv`. This server function converts the `ReportDocument` elements into HTML for display using `toHTML`.
3. **Downloading a Report**: Clicking "Download Report" in the previewer executes `report_render_and_compress`. This function uses the `Renderer` to generate an `.Rmd` file from the `ReportDocument` objects. The output is a `.zip` file containing the `.Rmd` report and a JSON file (for restoring the report).
4. **Loading a Report**: Clicking "Load Report" clears the current report and restores it from the JSON file contained within an uploaded `.zip` archive.
5. **Editing a `ReportDocument`**: Users can click an "Edit" button associated with a `ReportDocument` card in the previewer to modify its text elements. Custom edit functionalities can be specified for different content classes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe as a standalone section or on a different user-facing vignette?

class(report_doc)
#> [1] "ReportDocument"

# Add content using c() - note ReportDocument should be the first argument for S3 dispatch
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of the comments are too long, maybe we should make the code tighter?

Comment on lines +214 to +220
# card <- ReportCard$new()
# card$set_name("My Analysis Report")
# card$append_text("## Analysis Results")
# card$append_text("This is a summary of the analysis.")
# card$append_plot(my_ggplot)
# card$append_table(my_summary_table)
# card$append_src(code_string)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why comment out? shouldn't this be still available?

teal.reporter::code_chunk(code_string)
)
})
return(list(report_card = report_card))
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the no name approach, maybe even accepting reactives (as well as list of reactives).. It might make the transition to teal_data easier.

@@ -0,0 +1,394 @@
---
title: "New reporting in teal"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would love to keep our docs timeless and would recommend to avoid time-related phrases - even in the title. For example, if I open this document in a year or so - what does "new" actually mean?
Please just focus on explaining the current state as in typical technical manual. If we need to explain the deltas between the versions - that should be a separate release related entity (article, blog post, supplementary document etc.). As an example, we have done this in the past.

Copy link
Contributor

Choose a reason for hiding this comment

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

also, title shouldn't differ from a filename.

Copy link
Contributor

@gogonzo gogonzo left a comment

Choose a reason for hiding this comment

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

Please stick to explain how ReportDocument works without referring to old (soon to be deprecated classes). IMO ReportCard shouldn't appear in this document and we shouldn't explain why we did a refactor.

@gogonzo
Copy link
Contributor

gogonzo commented Jun 9, 2025

@m7pr is this PR still active?

@m7pr
Copy link
Contributor Author

m7pr commented Jun 9, 2025

@gogonzo no, in the end we started new PR here #1545

@m7pr m7pr closed this Jun 9, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jun 9, 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.

4 participants