During development of shiny modules, it can be helpful to see and test a module in the context of a shiny app. This function wraps the module UI and server functions in full shiny app for those purposes. You can also pass reactive values to the server function, to observe how your module reacts to them.
Usage
module2app(
module_ui = NULL,
module_server = NULL,
ui_args = list(),
server_args = list(),
ui_wrapper = shiny::basicPage,
options = list(test.mode = TRUE),
...
)
module2app_ui(
module_ui = NULL,
ui_args = list(),
ui_wrapper = shiny::basicPage
)
module2app_server(module_server = NULL, server_args = list())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.- 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
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.
See mixed_react_tree() for details on the shown input and return values.
If you are testing screenshots,
you are recommended to use get_screenshot_args_attr()
to screenshot only your actual module UI,
without the surrounding crow boilerplate.
See also
Other modules:
abort_if_reactive(),
get_screenshot_args_attr(),
mixed_react_tree
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)
}