Skip to contents

Wraps code that returns a shiny app into a function from your package's namespace, to pass to shinytest2::AppDriver's $new() method.

Usage

shinytest2_app_fn(
  code,
  package = utils::packageName(rlang::caller_env()) %||% pkgload::pkg_name()
)

Arguments

code

Code returning a shiny app, evaluated in your package's namespace in the background process.

package

Name of your package. Defaults to the package calling shinytest2_app_fn(), such as the one under test, or else to the package in the working directory.

Value

A function without arguments.

Details

Exported functions which return a shiny.appobj (such as those created with module2app()) can be passed to shinytest2::AppDriver$new() as is, e.g. AppDriver$new(my_app). shinytest2 then calls them in its background process after loading your package from source, as described in its package testing guide. Use shinytest2_app_fn() when the app needs arguments, or comes from other package code.

Do not pass pre-created app objects (my_app()), nor functions defined in a test file: both can run code from an outdated, installed version of your package, instead of its working tree.

Examples

if (FALSE) { # \dontrun{
local_app_driver(
  shinytest2_app_fn(module2app(counter_button_ui))
)
} # }