Skip to content

Add support for function type in TealAppDriver$new(app) - #1752

Merged
wangben718 merged 11 commits into
mainfrom
teal_app_driver_with_function
Oct 30, 2026
Merged

wangben718 merged 11 commits into
mainfrom
teal_app_driver_with_function

Conversation

@averissimo

@averissimo averissimo commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request

Note: we can replace app argument (deprecating it) in favor of using app_dir, however, if we do that should we also accept path to directory as argument?

Changes decription

  • Supports function in app argument of TealAppDriver$new(app)
    • This is the recommended way of using shinytest2 in package development and may be used to quiet some of the warnings
  • Fixes 2 typos

Copilot AI balanced review requested due to automatic review settings October 23, 2026 12:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Factory return-value handling and option forwarding introduce startup failures for documented inputs.

2 open issues
1 file not reviewed
  • man/TealAppDriver.Rd: Generated file
What changed in this PR

This PR extends TealAppDriver to accept application factories, supporting function-based setup for testing teal applications with shinytest2.

Changes:

  • Accepts functions alongside preconstructed teal_app objects and updates option forwarding.
  • Corrects the load-timeout environment variable and a method-name typo in documentation.
  • Documents factory support in the API reference and changelog.
File Description
R/​TealAppDriver.R Adds factory input handling, revises option forwarding, and corrects timeout and documentation typos.
NEWS.md Announces function-based application support.
man/​TealAppDriver.Rd Updates accepted input types and corrects the documented method name.

Review effort: Balanced

Comment thread R/TealAppDriver.R Outdated
Comment thread R/TealAppDriver.R Outdated
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

badge

Code Coverage Summary

Filename                          Stmts    Miss  Cover    Missing
------------------------------  -------  ------  -------  -----------------------------------------------------------------------------------------------------
R/after.R                            59      21  64.41%   42-52, 64, 69, 77-79, 81-89, 100, 104-105
R/checkmate.R                        24       0  100.00%
R/decorators-helpers.R               59       1  98.31%   113
R/dummy_functions.R                  61       2  96.72%   54, 56
R/include_css_js.R                   11       0  100.00%
R/init.R                            136       0  100.00%
R/module_bookmark_manager.R          99      54  45.45%   78-133
R/module_data_summary.R             177       8  95.48%   40, 50, 205, 236-240
R/module_filter_data.R               64       0  100.00%
R/module_filter_manager.R           210       7  96.67%   119-120, 316, 343, 355, 362-363
R/module_nested_tabs.R              411      42  89.78%   120, 178-183, 211, 315-330, 350-354, 409, 527-530, 534-537, 541-544
R/module_session_info.R              18       0  100.00%
R/module_snapshot_manager.R         276       9  96.74%   315-319, 386, 389-391
R/module_source_code.R               69       0  100.00%
R/module_teal_lockfile.R            131      53  59.54%   45-57, 60-62, 76, 86-88, 100-102, 110-119, 122, 124, 126-127, 142-146, 161-162, 177-186
R/module_teal_reporter.R            122       9  92.62%   60, 77-78, 81, 98, 128, 142, 144, 158
R/module_teal.R                     310      26  91.61%   137, 186, 242, 272-292, 322-323
R/module_transform_data.R           164      25  84.76%   77-81, 85-89, 106, 112, 119-120, 134-138, 188, 273-277
R/module_validate_error.R            73       0  100.00%
R/modules.R                         345      50  85.51%   170-174, 229-232, 332, 339, 353, 472, 570-576, 706-712, 725-733, 748-763, 796, 808-816
R/reporter_previewer_module.R        41      12  70.73%   41, 45, 68-85
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                 23       0  100.00%
R/teal_data_utils.R                  49       0  100.00%
R/teal_modifiers.R                   57       0  100.00%
R/teal_slices-store.R                29       0  100.00%
R/teal_slices.R                      48       2  95.83%   153-154
R/teal_transform_module.R            45       0  100.00%
R/TealAppDriver.R                   367     249  32.15%   80-92, 148, 156-185, 216-225, 235, 250-298, 323-586, 614-639, 694, 696-699, 718-732, 749-750, 761-778
R/utils.R                           290      48  83.45%   404-453, 541-550
R/validate_inputs.R                  60       0  100.00%
R/validations.R                      58       0  100.00%
R/zzz.R                              21       0  100.00%
TOTAL                              3937     618  84.30%

Diff against main

Filename             Stmts    Miss  Cover
-----------------  -------  ------  -------
R/TealAppDriver.R      +14      +5  +1.27%
TOTAL                  +14      +5  -0.07%

Results for commit: 82fee4d

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Unit Tests Summary

  1 files   36 suites   2m 40s ⏱️
491 tests 418 ✅ 73 💤 0 ❌
758 runs  685 ✅ 73 💤 0 ❌

Results for commit 82fee4d.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
module_teal 💔 $123.47$ $+3.63$ $0$ $0$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
shinytest2-init 👶 $+0.03$ TealAppDriver_throws_an_error_when_app_is_neither_a_teal_app_nor_a_function
shinytest2-init 👶 $+0.01$ e2e_TealAppDriver_with_a_function_as_app_sets_teal_options_in_the_app_process
shinytest2-init 👶 $+0.01$ e2e_TealAppDriver_with_a_function_as_app_starts_the_app_when_the_function_returns_a_shiny.appobj
shinytest2-init 👶 $+0.02$ e2e_TealAppDriver_with_a_function_as_app_starts_the_app_when_the_function_returns_a_teal_app

Results for commit b8e2a8f

♻️ This comment has been updated with latest results.

@wangben718
wangben718 force-pushed the teal_app_driver_with_function branch from 138e781 to e7ac4ae Compare October 27, 2026 02:32
@wangben718 wangben718 self-assigned this Oct 27, 2026
@wangben718

Copy link
Copy Markdown
Contributor

It is the right direction to support a function in TealAppDriver$new() and it's what shinytest2 recommends for package development. Widening the app check and switching to options = teal_options so the options are set before init() runs are also good changes.

However, the function path added by this PR originally didn't work end to end. (1) shinytest2 only starts the app if the function returns a shiny.appobj, so a function returning init(...) was never started. (2) Passing options as shiny_args is rejected by shinytest2 when the app is a function. (3) The function was copied to the background process with its link to the teal namespace, so R loaded the installed teal before library(teal) ran and the app used it instead of dev version.

My commit wraps the function so a returned teal_app is converted with shiny::shinyApp(), passes options to shinyApp() again, and moves the function's environment to the global environment before it's sent.

@llrs-roche llrs-roche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Many thanks for the updates, just some last (hopefully) comments

Comment thread tests/testthat/test-shinytest2-init.R Outdated
Comment thread tests/testthat/test-shinytest2-init.R Outdated
Comment thread tests/testthat/test-shinytest2-init.R
Comment thread R/TealAppDriver.R Outdated

@llrs-roche llrs-roche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the work is done and can be merged.
One las last tweak, could you fix the links CI that is failing (tmc is not on pharmaverse)? Thanks!

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wangben718
wangben718 enabled auto-merge (squash) October 29, 2026 22:02
@wangben718
wangben718 merged commit 3ded5a4 into main Oct 30, 2026
26 of 28 checks passed
@wangben718
wangben718 deleted the teal_app_driver_with_function branch October 30, 2026 08:21
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.

[Feature Request]: Add support for functions to be used as main argument in TealAppDriver

4 participants