Skip to contents

Wraps 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_serverand module_ui. server_args can be shiny::reactive()s, if corresponding argument in module_server accepts it. Named reactive server_args can change while the app runs (see module2app_bare()).

ui_wrapper

A function to wrap the resulting shiny::tagList() in. Must yield a full shiny UI, such as shiny::basicPage() or shiny::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 runApp call (these can be any of the following: "port", "launch.browser", "host", "quiet", "display.mode" and "test.mode"). You can also specify width and height parameters which provide a hint to the embedding environment about the ideal height/width for the app.

...

Arguments passed on to shiny::shinyApp

ui

The 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.

server

A function with three parameters: input, output, and session. The function is called once for each session ensuring that each app is independent.

onStart

A function that will be called before the app is actually run. This is only needed for shinyAppObj, since in the shinyAppDir case, a global.R file can be used for this purpose.

uiPattern

A regular expression that will be applied to each GET request to determine whether the ui should 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.

enableBookmarking

Can be one of "url", "server", or "disable". The default value, NULL, will respect the setting from any previous calls to enableBookmarking(). See enableBookmarking() 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 the unevaluated and evaluated tree, as text identical to the display of module2app() (see mixed_react_tree()).

  • reactlog: the raw events of shiny::reactlog() for this session, because tests and agents cannot call it in the app's process. Empty, unless the app runs with options(shiny.reactlog = TRUE), such as from local_app_driver(options = list(shiny.reactlog = TRUE)). The testbed's own reactives are labelled crow_*.

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:

Shiny.setInputValue("crow_server_args", {increment_by: 5})

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.