MockShinySession: Mock Shiny Session

Description Public fields Active bindings Methods Examples

Description

An R6 class suitable for testing that simulates the session parameter provided to Shiny server functions or modules.

Public fields

env

The environment associated with the session.

singletons

Hardcoded as empty. Needed for rendering HTML (i.e. renderUI)

clientData

Mock client data that always returns a size for plots

output

The shinyoutputs associated with the session

input

The reactive inputs associated with the session

userData

An environment initialized as empty.

progressStack

A stack of progress objects

Active bindings

returned

The value returned from the module

request

An empty environment where the request should be. The request isn't meaningfully mocked currently.

Methods

Public methods


Method reactlog()

No-op

Usage
MockShinySession$reactlog(logEntry)
Arguments
logEntry

Not used


Method incrementBusyCount()

No-op

Usage
MockShinySession$incrementBusyCount()

Method new()

Create a new MockShinySession

Usage
MockShinySession$new()

Method onFlush()

Define a callback to be invoked before a reactive flush

Usage
MockShinySession$onFlush(fun, once = TRUE)
Arguments
fun

The function to invoke

once

If TRUE, will only run once. Otherwise, will run every time reactives are flushed.


Method onFlushed()

Define a callback to be invoked after a reactive flush

Usage
MockShinySession$onFlushed(fun, once = TRUE)
Arguments
fun

The function to invoke

once

If TRUE, will only run once. Otherwise, will run every time reactives are flushed.


Method onEnded()

Define a callback to be invoked when the session ends

Usage
MockShinySession$onEnded(sessionEndedCallback)
Arguments
sessionEndedCallback

The callback to invoke when the session has ended.


Method isEnded()

Returns FALSE if the session has not yet been closed

Usage
MockShinySession$isEnded()

Method isClosed()

Returns FALSE if the session has not yet been closed

Usage
MockShinySession$isClosed()

Method close()

Closes the session

Usage
MockShinySession$close()

Method cycleStartAction()

Unsophisticated mock implementation that merely invokes the given callback immediately.

Usage
MockShinySession$cycleStartAction(callback)
Arguments
callback

The callback ato be invoked.


Method fileUrl()

Base64-encode the given file. Needed for image rendering.

Usage
MockShinySession$fileUrl(name, file, contentType = "application/octet-stream")
Arguments
name

Not used

file

The file to be encoded

contentType

The content type of the base64-encoded string


Method setInputs()

Sets reactive values associated with the session$inputs object and flushes the reactives.

Usage
MockShinySession$setInputs(...)
Arguments
...

The inputs to set.

Examples
s <- MockShinySession$new()
s$setInputs(x=1, y=2)

Method .scheduleTask()

An internal method which shouldn't be used by others.

Usage
MockShinySession$.scheduleTask(millis, callback)
Arguments
millis

The number of milliseconds on which to schedule a callback

callback

The function to schedule


Method elapse()

Simulate the passing of time by the given number of milliseconds.

Usage
MockShinySession$elapse(millis)
Arguments
millis

The number of milliseconds to advance time.


Method .now()

An internal method which shouldn't be used by others.

Usage
MockShinySession$.now()

Method defineOutput()

An internal method which shouldn't be used by others.

Usage
MockShinySession$defineOutput(name, func, label)
Arguments
name

The name of the output

func

The render definition

label

Not used


Method getOutput()

An internal method which shouldn't be used by others.

Usage
MockShinySession$getOutput(name)
Arguments
name

The name of the output


Method registerDataObj()

No-op

Usage
MockShinySession$registerDataObj(name, data, filterFunc)
Arguments
name

Not used

data

Not used

filterFunc

Not used


Method allowReconnect()

No-op

Usage
MockShinySession$allowReconnect(value)
Arguments
value

Not used


Method reload()

No-op

Usage
MockShinySession$reload()

Method resetBrush()

No-op

Usage
MockShinySession$resetBrush(brushId)
Arguments
brushId

Not used


Method sendCustomMessage()

No-op

Usage
MockShinySession$sendCustomMessage(type, message)
Arguments
type

Not used

message

Not used


Method sendBinaryMessage()

No-op

Usage
MockShinySession$sendBinaryMessage(type, message)
Arguments
type

Not used

message

Not used


Method sendInputMessage()

No-op

Usage
MockShinySession$sendInputMessage(inputId, message)
Arguments
inputId

Not used

message

Not used


Method setBookmarkExclude()

No-op

Usage
MockShinySession$setBookmarkExclude(names)
Arguments
names

Not used


Method getBookmarkExclude()

No-op

Usage
MockShinySession$getBookmarkExclude()

Method onBookmark()

No-op

Usage
MockShinySession$onBookmark(fun)
Arguments
fun

Not used


Method onBookmarked()

No-op

Usage
MockShinySession$onBookmarked(fun)
Arguments
fun

Not used


Method doBookmark()

No-op

Usage
MockShinySession$doBookmark()

Method onRestore()

No-op

Usage
MockShinySession$onRestore(fun)
Arguments
fun

Not used


Method onRestored()

No-op

Usage
MockShinySession$onRestored(fun)
Arguments
fun

Not used


Method exportTestValues()

No-op

Usage
MockShinySession$exportTestValues()

Method getTestSnapshotUrl()

No-op

Usage
MockShinySession$getTestSnapshotUrl(
  input = TRUE,
  output = TRUE,
  export = TRUE,
  format = "json"
)
Arguments
input

Not used

output

Not used

export

Not used

format

Not used


Method ns()

Returns the given id prefixed by mock-session-.

Usage
MockShinySession$ns(id)
Arguments
id

The id to modify.


Method flushReact()

Trigger a reactive flush right now.

Usage
MockShinySession$flushReact()

Method makeScope()

Usage
MockShinySession$makeScope(namespace)

Method clone()

The objects of this class are cloneable with this method.

Usage
MockShinySession$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

1
2
3
4
5
6
## ------------------------------------------------
## Method `MockShinySession$setInputs`
## ------------------------------------------------

s <- MockShinySession$new()
s$setInputs(x=1, y=2)

tomkuipers1402/shiny documentation built on Feb. 13, 2020, 7:22 p.m.