Show a module in a testbed app, without its inputs and outputs
Source:R/module2app.R
module2app_bare.RdWraps the UI and server functions of a module in a shiny app,
like module2app().
Unlike module2app(),
the app shows only the module UI:
it does not show the server arguments and return values.
Usage
module2app_bare_ui(
module_ui = NULL,
ui_args = list(),
ui_wrapper = shiny::basicPage
)
module2app_bare_server(module_server = NULL, server_args = list())
module2app_bare(
module_ui = NULL,
module_server = NULL,
ui_args = list(),
server_args = list(),
ui_wrapper = shiny::basicPage,
options = list(test.mode = TRUE),
...
)Arguments
- module_ui, module_server
Module functions.
- ui_args, server_args
Additional arguments passed to
module_serverandmodule_ui.server_argscan beshiny::reactive()s, if corresponding argument inmodule_serveraccepts it. Named reactiveserver_argscan change while the app runs (seemodule2app_bare()).- ui_wrapper
A function to wrap the resulting
shiny::tagList()in. Must yield a full shiny UI, such asshiny::basicPage()orshiny::bootstrapPage(). For maximum reusability of a module, avoid depending on the wrapper and only return "vanilla" UI.- options
Named options that should be passed to the
runAppcall (these can be any of the following: "port", "launch.browser", "host", "quiet", "display.mode" and "test.mode"). You can also specifywidthandheightparameters which provide a hint to the embedding environment about the ideal height/width for the app.- ...
Arguments passed on to
shiny::shinyAppuiThe UI definition of the app (for example, a call to
fluidPage()with nested controls).If bookmarking is enabled (see
enableBookmarking), this must be a single argument function that returns the UI definition.serverA function with three parameters:
input,output, andsession. The function is called once for each session ensuring that each app is independent.onStartA function that will be called before the app is actually run. This is only needed for
shinyAppObj, since in theshinyAppDircase, aglobal.Rfile can be used for this purpose.uiPatternA regular expression that will be applied to each
GETrequest to determine whether theuishould be used to handle the request. Note that the entire request path must match the regular expression in order for the match to be considered successful.enableBookmarkingCan be one of
"url","server", or"disable". The default value,NULL, will respect the setting from any previous calls toenableBookmarking(). SeeenableBookmarking()for more information on bookmarking your app.
Details
Use module2app() when a person looks at the module.
Use module2app_bare() when a program inspects the module,
such as a test or a coding agent:
Screenshots of the whole page show only the module UI.
The program reads the server arguments and return values from the exported values (see details), not from the page.
Both testbeds mount the module with the ID test_object
and export these values for shinytest2::AppDriver's $get_value():
res: the return value of the module server, called if it is a reactive.server_args,returns: the server arguments and the return values, each a list of theunevaluatedandevaluatedtree, as text identical to the display ofmodule2app()(seemixed_react_tree()).reactlog: the raw events ofshiny::reactlog()for this session, because tests and agents cannot call it in the app's process. Empty, unless the app runs withoptions(shiny.reactlog = TRUE), such as fromlocal_app_driver(options = list(shiny.reactlog = TRUE)). The testbed's own reactives are labelledcrow_*.
module2app() displays the evaluated trees as outputs,
which depend on, and thus change, the module's reactive graph
(see mixed_react_tree()).
module2app_bare() has no such outputs;
it evaluates the trees only when a test requests them.
Its reactive graph is thus the same as that of an app
which only uses the module.
Functions
module2app_bare_ui(): UI with only the module UI.module2app_bare_server(): Server with only the module server.
Changing server arguments while the app runs
Both testbeds read the hidden input crow_server_args,
a JSON object keyed by server argument name.
Its values replace the values of these arguments,
for all sessions of the app.
A null restores the value passed at start.
The module receives each named reactive in server_args
wrapped in a shiny::reactive(),
so it cannot set the original shiny::reactiveVal().
Other server arguments are fixed at start.
The displayed and exported server_args show the reactives as passed,
but evaluate to the current values.
From R, through shinytest2::AppDriver (see local_app_driver()):
driver$set_inputs(
crow_server_args = list(increment_by = 5),
allow_no_input_binding_ = TRUE
)From the browser console:
Values can be any JSON value,
which shiny converts with jsonlite::fromJSON(simplifyVector = FALSE):
e.g. 5 becomes 5L, 2.5 a double, true TRUE,
and arrays and objects become lists.
The input accepts only JSON, never R code,
because the app does not check the origin of websocket connections:
any web page open in the same browser can send this input.
Changing an unknown or a non-reactive argument changes nothing. The error goes to the app's standard error and a notification, because an error would end the session.
See also
Other modules:
abort_if_reactive(),
get_screenshot_args_attr(),
mixed_react_tree,
module2app_ui()
Other shinytest2:
get_screenshot_args_attr(),
local_app_driver(),
shinytest2_app_fn()