EVOLUTION-MANAGER
Edit File: MockShinySession.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: Mock Shiny Session</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 MockShinySession {shiny}"><tr><td>MockShinySession {shiny}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Mock Shiny Session</h2> <h3>Description</h3> <p>An R6 class suitable for testing purposes. Simulates, to the extent possible, the behavior of the <code>ShinySession</code> class. The <code>session</code> parameter provided to Shiny server functions and modules is an instance of a <code>ShinySession</code> in normal operation. </p> <p>Most kinds of module and server testing do not require this class be instantiated manually. See instead <code><a href="testServer.html">testServer()</a></code>. </p> <p>In order to support advanced usage, instances of <code>MockShinySession</code> are <strong>unlocked</strong> so that public methods and fields of instances may be modified. For example, in order to test authentication workflows, the <code>user</code> or <code>groups</code> fields may be overridden. Modified instances of <code>MockShinySession</code> may then be passed explicitly as the <code>session</code> argument of <code><a href="testServer.html">testServer()</a></code>. </p> <h3>Public fields</h3> <div class="r6-fields"> <dl> <dt><code>env</code></dt><dd><p>The environment associated with the session.</p> </dd> <dt><code>returned</code></dt><dd><p>The value returned by the module under test.</p> </dd> <dt><code>singletons</code></dt><dd><p>Hardcoded as empty. Needed for rendering HTML (i.e. renderUI).</p> </dd> <dt><code>clientData</code></dt><dd><p>Mock client data that always returns a size for plots.</p> </dd> <dt><code>output</code></dt><dd><p>The shinyoutputs associated with the session.</p> </dd> <dt><code>input</code></dt><dd><p>The reactive inputs associated with the session.</p> </dd> <dt><code>userData</code></dt><dd><p>An environment initialized as empty.</p> </dd> <dt><code>progressStack</code></dt><dd><p>A stack of progress objects.</p> </dd> <dt><code>token</code></dt><dd><p>On a real <code>ShinySession</code>, used to identify this instance in URLs.</p> </dd> <dt><code>cache</code></dt><dd><p>The session cache MemoryCache.</p> </dd> <dt><code>appcache</code></dt><dd><p>The app cache MemoryCache.</p> </dd> <dt><code>restoreContext</code></dt><dd><p>Part of bookmarking support in a real <code>ShinySession</code> but always <code>NULL</code> for a <code>MockShinySession</code>.</p> </dd> <dt><code>groups</code></dt><dd><p>Character vector of groups associated with an authenticated user. Always <code>NULL</code> for a <code>MockShinySesion</code>.</p> </dd> <dt><code>user</code></dt><dd><p>The username of an authenticated user. Always <code>NULL</code> for a <code>MockShinySession</code>.</p> </dd> </dl> </div> <h3>Active bindings</h3> <div class="r6-active-bindings"> <dl> <dt><code>files</code></dt><dd><p>For internal use only.</p> </dd> <dt><code>downloads</code></dt><dd><p>For internal use only.</p> </dd> <dt><code>closed</code></dt><dd><p>Deprecated in <code>ShinySession</code> and signals an error.</p> </dd> <dt><code>session</code></dt><dd><p>Deprecated in ShinySession and signals an error.</p> </dd> <dt><code>request</code></dt><dd><p>An empty environment where the request should be. The request isn't meaningfully mocked currently.</p> </dd> </dl> </div> <h3>Methods</h3> <h4>Public methods</h4> <ul> <li> <p><a href="#method-new"><code>MockShinySession$new()</code></a> </p> </li> <li> <p><a href="#method-onFlush"><code>MockShinySession$onFlush()</code></a> </p> </li> <li> <p><a href="#method-onFlushed"><code>MockShinySession$onFlushed()</code></a> </p> </li> <li> <p><a href="#method-onEnded"><code>MockShinySession$onEnded()</code></a> </p> </li> <li> <p><a href="#method-isEnded"><code>MockShinySession$isEnded()</code></a> </p> </li> <li> <p><a href="#method-isClosed"><code>MockShinySession$isClosed()</code></a> </p> </li> <li> <p><a href="#method-close"><code>MockShinySession$close()</code></a> </p> </li> <li> <p><a href="#method-cycleStartAction"><code>MockShinySession$cycleStartAction()</code></a> </p> </li> <li> <p><a href="#method-fileUrl"><code>MockShinySession$fileUrl()</code></a> </p> </li> <li> <p><a href="#method-setInputs"><code>MockShinySession$setInputs()</code></a> </p> </li> <li> <p><a href="#method-.scheduleTask"><code>MockShinySession$.scheduleTask()</code></a> </p> </li> <li> <p><a href="#method-elapse"><code>MockShinySession$elapse()</code></a> </p> </li> <li> <p><a href="#method-.now"><code>MockShinySession$.now()</code></a> </p> </li> <li> <p><a href="#method-defineOutput"><code>MockShinySession$defineOutput()</code></a> </p> </li> <li> <p><a href="#method-getOutput"><code>MockShinySession$getOutput()</code></a> </p> </li> <li> <p><a href="#method-ns"><code>MockShinySession$ns()</code></a> </p> </li> <li> <p><a href="#method-flushReact"><code>MockShinySession$flushReact()</code></a> </p> </li> <li> <p><a href="#method-makeScope"><code>MockShinySession$makeScope()</code></a> </p> </li> <li> <p><a href="#method-setEnv"><code>MockShinySession$setEnv()</code></a> </p> </li> <li> <p><a href="#method-setReturned"><code>MockShinySession$setReturned()</code></a> </p> </li> <li> <p><a href="#method-getReturned"><code>MockShinySession$getReturned()</code></a> </p> </li> <li> <p><a href="#method-genId"><code>MockShinySession$genId()</code></a> </p> </li> <li> <p><a href="#method-rootScope"><code>MockShinySession$rootScope()</code></a> </p> </li> <li> <p><a href="#method-unhandledError"><code>MockShinySession$unhandledError()</code></a> </p> </li> <li> <p><a href="#method-freezeValue"><code>MockShinySession$freezeValue()</code></a> </p> </li> <li> <p><a href="#method-onSessionEnded"><code>MockShinySession$onSessionEnded()</code></a> </p> </li> <li> <p><a href="#method-registerDownload"><code>MockShinySession$registerDownload()</code></a> </p> </li> <li> <p><a href="#method-getCurrentOutputInfo"><code>MockShinySession$getCurrentOutputInfo()</code></a> </p> </li> <li> <p><a href="#method-clone"><code>MockShinySession$clone()</code></a> </p> </li></ul> <hr> <a id="method-new"></a> <h4>Method <code>new()</code></h4> <p>Create a new MockShinySession. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$new()</pre></div> <hr> <a id="method-onFlush"></a> <h4>Method <code>onFlush()</code></h4> <p>Define a callback to be invoked before a reactive flush </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$onFlush(fun, once = TRUE)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>fun</code></dt><dd><p>The function to invoke</p> </dd> <dt><code>once</code></dt><dd><p>If <code>TRUE</code>, will only run once. Otherwise, will run every time reactives are flushed.</p> </dd> </dl> </div> <hr> <a id="method-onFlushed"></a> <h4>Method <code>onFlushed()</code></h4> <p>Define a callback to be invoked after a reactive flush </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$onFlushed(fun, once = TRUE)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>fun</code></dt><dd><p>The function to invoke</p> </dd> <dt><code>once</code></dt><dd><p>If <code>TRUE</code>, will only run once. Otherwise, will run every time reactives are flushed.</p> </dd> </dl> </div> <hr> <a id="method-onEnded"></a> <h4>Method <code>onEnded()</code></h4> <p>Define a callback to be invoked when the session ends </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$onEnded(sessionEndedCallback)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>sessionEndedCallback</code></dt><dd><p>The callback to invoke when the session has ended.</p> </dd> </dl> </div> <hr> <a id="method-isEnded"></a> <h4>Method <code>isEnded()</code></h4> <p>Returns <code>FALSE</code> if the session has not yet been closed </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$isEnded()</pre></div> <hr> <a id="method-isClosed"></a> <h4>Method <code>isClosed()</code></h4> <p>Returns <code>FALSE</code> if the session has not yet been closed </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$isClosed()</pre></div> <hr> <a id="method-close"></a> <h4>Method <code>close()</code></h4> <p>Closes the session </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$close()</pre></div> <hr> <a id="method-cycleStartAction"></a> <h4>Method <code>cycleStartAction()</code></h4> <p>Unsophisticated mock implementation that merely invokes </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$cycleStartAction(callback)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>callback</code></dt><dd><p>The callback to be invoked.</p> </dd> </dl> </div> <hr> <a id="method-fileUrl"></a> <h4>Method <code>fileUrl()</code></h4> <p>Base64-encode the given file. Needed for image rendering. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$fileUrl(name, file, contentType = "application/octet-stream")</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>name</code></dt><dd><p>Not used</p> </dd> <dt><code>file</code></dt><dd><p>The file to be encoded</p> </dd> <dt><code>contentType</code></dt><dd><p>The content type of the base64-encoded string</p> </dd> </dl> </div> <hr> <a id="method-setInputs"></a> <h4>Method <code>setInputs()</code></h4> <p>Sets reactive values associated with the <code>session$inputs</code> object and flushes the reactives. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$setInputs(...)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>...</code></dt><dd><p>The inputs to set. These arguments are processed with <code><a href="../../rlang/html/list2.html">rlang::list2()</a></code> and so are <em><a href="../../rlang/html/dyn-dots.html">dynamic</a></em>. Input names may not be duplicated.</p> </dd> </dl> </div> <h5>Examples</h5> <div class="r example copy"> <pre>\dontrun{ session$setInputs(x=1, y=2) } </pre> </div> <hr> <a id="method-.scheduleTask"></a> <h4>Method <code>.scheduleTask()</code></h4> <p>An internal method which shouldn't be used by others. Schedules <code>callback</code> for execution after some number of <code>millis</code> milliseconds. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$.scheduleTask(millis, callback)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>millis</code></dt><dd><p>The number of milliseconds on which to schedule a callback</p> </dd> <dt><code>callback</code></dt><dd><p>The function to schedule.</p> </dd> </dl> </div> <hr> <a id="method-elapse"></a> <h4>Method <code>elapse()</code></h4> <p>Simulate the passing of time by the given number of milliseconds. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$elapse(millis)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>millis</code></dt><dd><p>The number of milliseconds to advance time.</p> </dd> </dl> </div> <hr> <a id="method-.now"></a> <h4>Method <code>.now()</code></h4> <p>An internal method which shouldn't be used by others. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$.now()</pre></div> <h5>Returns</h5> <p>Elapsed time in milliseconds. </p> <hr> <a id="method-defineOutput"></a> <h4>Method <code>defineOutput()</code></h4> <p>An internal method which shouldn't be used by others. Defines an output in a way that sets private$currentOutputName appropriately. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$defineOutput(name, func, label)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>name</code></dt><dd><p>The name of the output.</p> </dd> <dt><code>func</code></dt><dd><p>The render definition.</p> </dd> <dt><code>label</code></dt><dd><p>Not used.</p> </dd> </dl> </div> <hr> <a id="method-getOutput"></a> <h4>Method <code>getOutput()</code></h4> <p>An internal method which shouldn't be used by others. Forces evaluation of any reactive dependencies of the output function. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$getOutput(name)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>name</code></dt><dd><p>The name of the output.</p> </dd> </dl> </div> <h5>Returns</h5> <p>The return value of the function responsible for rendering the output. </p> <hr> <a id="method-ns"></a> <h4>Method <code>ns()</code></h4> <p>Returns the given id prefixed by this namespace's id. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$ns(id)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>id</code></dt><dd><p>The id to prefix with a namespace id.</p> </dd> </dl> </div> <h5>Returns</h5> <p>The id with a namespace prefix. </p> <hr> <a id="method-flushReact"></a> <h4>Method <code>flushReact()</code></h4> <p>Trigger a reactive flush right now. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$flushReact()</pre></div> <hr> <a id="method-makeScope"></a> <h4>Method <code>makeScope()</code></h4> <p>Create and return a namespace-specific session proxy. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$makeScope(namespace)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>namespace</code></dt><dd><p>Character vector indicating a namespace.</p> </dd> </dl> </div> <h5>Returns</h5> <p>A new session proxy. </p> <hr> <a id="method-setEnv"></a> <h4>Method <code>setEnv()</code></h4> <p>Set the environment associated with a testServer() call, but only if it has not previously been set. This ensures that only the environment of the outermost module under test is the one retained. In other words, the first assignment wins. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$setEnv(env)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>env</code></dt><dd><p>The environment to retain.</p> </dd> </dl> </div> <h5>Returns</h5> <p>The provided <code>env</code>. </p> <hr> <a id="method-setReturned"></a> <h4>Method <code>setReturned()</code></h4> <p>Set the value returned by the module call and proactively flush. Note that this method may be called multiple times if modules are nested. The last assignment, corresponding to an invocation of setReturned() in the outermost module, wins. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$setReturned(value)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>value</code></dt><dd><p>The value returned from the module</p> </dd> </dl> </div> <h5>Returns</h5> <p>The provided <code>value</code>. </p> <hr> <a id="method-getReturned"></a> <h4>Method <code>getReturned()</code></h4> <p>Get the value returned by the module call. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$getReturned()</pre></div> <h5>Returns</h5> <p>The value returned by the module call </p> <hr> <a id="method-genId"></a> <h4>Method <code>genId()</code></h4> <p>Generate a distinct character identifier for use as a proxy namespace. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$genId()</pre></div> <h5>Returns</h5> <p>A character identifier unique to the current session. </p> <hr> <a id="method-rootScope"></a> <h4>Method <code>rootScope()</code></h4> <p>Provides a way to access the root <code>MockShinySession</code> from any descendant proxy. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$rootScope()</pre></div> <h5>Returns</h5> <p>The root <code>MockShinySession</code>. </p> <hr> <a id="method-unhandledError"></a> <h4>Method <code>unhandledError()</code></h4> <p>Called by observers when a reactive expression errors. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$unhandledError(e)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>e</code></dt><dd><p>An error object.</p> </dd> </dl> </div> <hr> <a id="method-freezeValue"></a> <h4>Method <code>freezeValue()</code></h4> <p>Freeze a value until the flush cycle completes. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$freezeValue(x, name)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>x</code></dt><dd><p>A <code>ReactiveValues</code> object.</p> </dd> <dt><code>name</code></dt><dd><p>The name of a reactive value within <code>x</code>.</p> </dd> </dl> </div> <hr> <a id="method-onSessionEnded"></a> <h4>Method <code>onSessionEnded()</code></h4> <p>Registers the given callback to be invoked when the session is closed (i.e. the connection to the client has been severed). The return value is a function which unregisters the callback. If multiple callbacks are registered, the order in which they are invoked is not guaranteed. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$onSessionEnded(sessionEndedCallback)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>sessionEndedCallback</code></dt><dd><p>Function to call when the session ends.</p> </dd> </dl> </div> <hr> <a id="method-registerDownload"></a> <h4>Method <code>registerDownload()</code></h4> <p>Associated a downloadable file with the session. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$registerDownload(name, filename, contentType, content)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>name</code></dt><dd><p>The un-namespaced output name to associate with the downloadable file.</p> </dd> <dt><code>filename</code></dt><dd><p>A string or function designating the name of the file.</p> </dd> <dt><code>contentType</code></dt><dd><p>A string of the content type of the file. Not used by <code>MockShinySession</code>.</p> </dd> <dt><code>content</code></dt><dd><p>A function that takes a single argument file that is a file path (string) of a nonexistent temp file, and writes the content to that file path. (Reactive values and functions may be used from this function.)</p> </dd> </dl> </div> <hr> <a id="method-getCurrentOutputInfo"></a> <h4>Method <code>getCurrentOutputInfo()</code></h4> <p>Get information about the output that is currently being executed. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$getCurrentOutputInfo()</pre></div> <h5>Returns</h5> <p>A list with with the <code>name</code> of the output. If no output is currently being executed, this will return <code>NULL</code>. output, or <code>NULL</code> if no output is currently executing. </p> <hr> <a id="method-clone"></a> <h4>Method <code>clone()</code></h4> <p>The objects of this class are cloneable with this method. </p> <h5>Usage</h5> <div class="r"><pre>MockShinySession$clone(deep = FALSE)</pre></div> <h5>Arguments</h5> <div class="arguments"> <dl> <dt><code>deep</code></dt><dd><p>Whether to make a deep clone.</p> </dd> </dl> </div> <h3>Examples</h3> <pre> ## ------------------------------------------------ ## Method `MockShinySession$setInputs` ## ------------------------------------------------ ## Not run: session$setInputs(x=1, y=2) ## End(Not run) </pre> <hr /><div style="text-align: center;">[Package <em>shiny</em> version 1.5.0 <a href="00Index.html">Index</a>]</div> </body></html>