EVOLUTION-MANAGER
Edit File: testServer.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Reactive testing for Shiny server functions and modules</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for testServer {shiny}"><tr><td>testServer {shiny}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Reactive testing for Shiny server functions and modules</h2> <h3>Description</h3> <p>A way to test the reactive interactions in Shiny applications. Reactive interactions are defined in the server function of applications and in modules. </p> <h3>Usage</h3> <pre> testServer(app = NULL, expr, args = list(), session = MockShinySession$new()) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>app</code></td> <td> <p>The path to an application or module to test. In addition to paths, applications may be represented by any object suitable for coercion to an <code>appObj</code> by <code><a href="shiny.appobj.html">as.shiny.appobj</a></code>. Application server functions must include a <code>session</code> argument in order to be tested. If <code>app</code> is <code>NULL</code> or not supplied, the nearest enclosing directory that is a Shiny app, starting with the current directory, is used.</p> </td></tr> <tr valign="top"><td><code>expr</code></td> <td> <p>Test code containing expectations. The test expression will run in the server function environment, meaning that the parameters of the server function (e.g. <code>input</code>, <code>output</code>, and <code>session</code>) will be available along with any other values created inside of the server function.</p> </td></tr> <tr valign="top"><td><code>args</code></td> <td> <p>Additional arguments to pass to the module function. If <code>app</code> is a module, and no <code>id</code> argument is provided, one will be generated and supplied automatically.</p> </td></tr> <tr valign="top"><td><code>session</code></td> <td> <p>The <code><a href="MockShinySession.html">MockShinySession</a></code> object to use as the <a href="domains.html">reactive domain</a>. The same session object is used as the domain both during invocation of the server or module under test and during evaluation of <code>expr</code>.</p> </td></tr> </table> <h3>Examples</h3> <pre> server <- function(id, multiplier = 2, prefix = "I am ") { moduleServer(id, function(input, output, session) { myreactive <- reactive({ input$x * multiplier }) output$txt <- renderText({ paste0(prefix, myreactive()) }) }) } testServer(server, args = list(multiplier = 2), { session$setInputs(x = 1) # You're also free to use third-party # testing packages like testthat: # expect_equal(myreactive(), 2) stopifnot(myreactive() == 2) stopifnot(output$txt == "I am 2") session$setInputs(x = 2) stopifnot(myreactive() == 4) stopifnot(output$txt == "I am 4") # Any additional arguments, below, are passed along to the module. }) </pre> <hr /><div style="text-align: center;">[Package <em>shiny</em> version 1.5.0 <a href="00Index.html">Index</a>]</div> </body></html>