| MockShinySession | R Documentation |
An R6 class suitable for testing purposes. Simulates, to the
extent possible, the behavior of the ShinySession class. The session
parameter provided to Shiny server functions and modules is an instance of
a ShinySession in normal operation.
Most kinds of module and server testing do not require this class be
instantiated manually. See instead testServer().
In order to support advanced usage, instances of MockShinySession are
unlocked so that public methods and fields of instances may be
modified. For example, in order to test authentication workflows, the
user or groups fields may be overridden. Modified instances of
MockShinySession may then be passed explicitly as the session argument
of testServer().
envThe environment associated with the session.
returnedThe value returned by the module under test.
singletonsHardcoded as empty. Needed for rendering HTML (i.e. renderUI).
clientDataMock client data that always returns a size for plots.
outputThe shinyoutputs associated with the session.
inputThe reactive inputs associated with the session.
userDataAn environment initialized as empty.
progressStackA stack of progress objects.
tokenOn a real ShinySession, used to identify this instance in URLs.
cacheThe session cache object.
appcacheThe app cache object.
restoreContextPart of bookmarking support in a real
ShinySession but always NULL for a MockShinySession.
groupsCharacter vector of groups associated with an authenticated
user. Always NULL for a MockShinySesion.
userThe username of an authenticated user. Always NULL for a
MockShinySession.
optionsA list containing session-level shinyOptions.
filesFor internal use only.
downloadsFor internal use only.
closedDeprecated in ShinySession and signals an error.
sessionDeprecated in ShinySession and signals an error.
requestAn empty environment where the request should be. The request isn't meaningfully mocked currently.
new()Create a new MockShinySession.
MockShinySession$new()
onFlush()Define a callback to be invoked before a reactive flush
MockShinySession$onFlush(fun, once = TRUE)
funThe function to invoke
onceIf TRUE, will only run once. Otherwise, will run every time reactives are flushed.
onFlushed()Define a callback to be invoked after a reactive flush
MockShinySession$onFlushed(fun, once = TRUE)
funThe function to invoke
onceIf TRUE, will only run once. Otherwise, will run every time reactives are flushed.
onEnded()Define a callback to be invoked when the session ends
MockShinySession$onEnded(sessionEndedCallback)
sessionEndedCallbackThe callback to invoke when the session has ended.
isEnded()Returns FALSE if the session has not yet been closed
MockShinySession$isEnded()
isClosed()Returns FALSE if the session has not yet been closed
MockShinySession$isClosed()
close()Closes the session
MockShinySession$close()
cycleStartAction()Unsophisticated mock implementation that merely invokes
MockShinySession$cycleStartAction(callback)
callbackThe callback to be invoked.
fileUrl()Base64-encode the given file. Needed for image rendering.
MockShinySession$fileUrl(name, file, contentType = "application/octet-stream")
nameNot used
fileThe file to be encoded
contentTypeThe content type of the base64-encoded string
setInputs()Sets reactive values associated with the session$inputs
object and flushes the reactives.
MockShinySession$setInputs(...)
...The inputs to set. These arguments are processed with
rlang::list2() and so are dynamic. Input names
may not be duplicated.
\dontrun{
session$setInputs(x=1, y=2)
}
.scheduleTask()An internal method which shouldn't be used by others.
Schedules callback for execution after some number of millis
milliseconds.
MockShinySession$.scheduleTask(millis, callback)
millisThe number of milliseconds on which to schedule a callback
callbackThe function to schedule.
elapse()Simulate the passing of time by the given number of milliseconds.
MockShinySession$elapse(millis)
millisThe number of milliseconds to advance time.
.now()An internal method which shouldn't be used by others.
MockShinySession$.now()
Elapsed time in milliseconds.
defineOutput()An internal method which shouldn't be used by others. Defines an output in a way that sets private$currentOutputName appropriately.
MockShinySession$defineOutput(name, func, label)
nameThe name of the output.
funcThe render definition.
labelNot used.
getOutput()An internal method which shouldn't be used by others. Forces evaluation of any reactive dependencies of the output function.
MockShinySession$getOutput(name)
nameThe name of the output.
The return value of the function responsible for rendering the output.
ns()Returns the given id prefixed by this namespace's id.
MockShinySession$ns(id)
idThe id to prefix with a namespace id.
The id with a namespace prefix.
flushReact()Trigger a reactive flush right now.
MockShinySession$flushReact()
makeScope()Create and return a namespace-specific session proxy.
MockShinySession$makeScope(namespace)
namespaceCharacter vector indicating a namespace.
A new session proxy.
setEnv()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.
MockShinySession$setEnv(env)
envThe environment to retain.
The provided env.
setReturned()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.
MockShinySession$setReturned(value)
valueThe value returned from the module
The provided value.
getReturned()Get the value returned by the module call.
MockShinySession$getReturned()
The value returned by the module call
genId()Generate a distinct character identifier for use as a proxy namespace.
MockShinySession$genId()
A character identifier unique to the current session.
rootScope()Provides a way to access the root MockShinySession from
any descendant proxy.
MockShinySession$rootScope()
The root MockShinySession.
onUnhandledError()Add an unhandled error callback.
MockShinySession$onUnhandledError(callback)
callbackThe callback to add, which should accept an error object as its first argument.
A deregistration function.
unhandledError()Called by observers when a reactive expression errors.
MockShinySession$unhandledError(e, close = TRUE)
eAn error object.
closeIf TRUE, the session will be closed after the error is
handled, defaults to FALSE.
freezeValue()Freeze a value until the flush cycle completes.
MockShinySession$freezeValue(x, name)
xA ReactiveValues object.
nameThe name of a reactive value within x.
onSessionEnded()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.
MockShinySession$onSessionEnded(sessionEndedCallback)
sessionEndedCallbackFunction to call when the session ends.
registerDownload()Associated a downloadable file with the session.
MockShinySession$registerDownload(name, filename, contentType, content)
nameThe un-namespaced output name to associate with the downloadable file.
filenameA string or function designating the name of the file.
contentTypeA string of the content type of the file. Not used by
MockShinySession.
contentA 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.)
getCurrentOutputInfo()Get information about the output that is currently being executed.
MockShinySession$getCurrentOutputInfo()
A list with with the name of the output. If no output is
currently being executed, this will return NULL.
output, or NULL if no output is currently executing.
clone()The objects of this class are cloneable with this method.
MockShinySession$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------
## Method `MockShinySession$setInputs`
## ------------------------------------------------
## Not run:
session$setInputs(x=1, y=2)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.