Wraps the UI and server functions of a module in a shiny app, to develop and test the module. Around the module UI, the app shows what goes into and comes out of the module server:
above, the server arguments (
server_args),below, the return values of the module server.
Usage
module2app_ui(
module_ui = NULL,
ui_args = list(),
ui_wrapper = shiny::basicPage
)
module2app_server(module_server = NULL, server_args = list())
module2app(
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
It shows each as an unevaluated and an evaluated tree
(see mixed_react_tree()),
which collapse when you click their heading.
Collapsed trees still update.
You can pass reactive values as server arguments,
to observe how your module reacts to them.
For the module UI alone, without these displays, use module2app_bare().
If you only want to test the server logic of a module,
you don't need this function.
You can just pass the module server function to shiny::testServer().
Hadley Wickhams Mastering Shiny as a section on
testing modules.
Both testbeds export the server arguments and return values
for tests,
and accept changes to reactive server_args while the app runs
(see module2app_bare()).
Screenshots from local_app_driver() show only your actual module UI,
without the displays of server arguments and return values.
Functions
module2app_ui(): UI with the module UI between the displays of server arguments and return values. It passesui_wrapperfour arguments: the heading, the server arguments, the module UI and the return values. Aui_wrapperwith four parameters can arrange them, such as in sidebars.module2app_server(): Server with the module server and the displays of server arguments and return values.
See also
Other modules:
abort_if_reactive(),
get_screenshot_args_attr(),
mixed_react_tree,
module2app_bare_ui()
Examples
# ui wrapper with a custom function
ui_wrapper <- function(...) {
shiny::navbarPage(
shiny::tabPanel(title = "A Panel", ...),
title = "Testbed with Navbar"
)
}
# you can provide your own ui wrapper with partialised arguments
if (elf::is_installed2("bslib")) {
# current bootstrap theme via bslib
theme <- bslib::bs_theme(version = 5)
ui_wrapper <- purrr::partial(shiny::bootstrapPage, theme = theme)
}
# ui wrapper which arranges the parts of the testbed
if (elf::is_installed2("bslib")) {
ui_wrapper <- function(heading, inputs, module, returns) {
bslib::page_fluid(
heading,
bslib::layout_sidebar(
sidebar = bslib::sidebar(inputs),
bslib::layout_sidebar(
sidebar = bslib::sidebar(returns, position = "right"),
module
)
)
)
}
}
