Skip to contents

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_serverand module_ui. server_args can be shiny::reactive()s, if corresponding argument in module_server accepts it.

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

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.

Functions

  • module2app_ui(): UI

  • module2app_server(): Server

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)
}