Methods
Method new()
Create a new tidymodules module.
Usage
TidyModule$new(
id = NULL,
inherit = TRUE,
group = NULL,
parent = NULL,
collision = FALSE
)
Arguments
id
Unique Id to assign to the module. Default to a generated Id using module's class and order of initialization.
inherit
logical value indicating if a nested module should inherits the parent's input ports. Default to TRUE
group
Module group name. Added to module's Id to make it unique. Optional
parent
Parent module. Need to be specified when creating a dynamic nested module. Optional
collision
Allow module id collision. Default to false.
Id collision happens when you try to creating the same module (same Id) twice at the same time. Optional
Returns
A new TidyModule
object.
Method ns()
namespace function used to generate unique Id for HTML elements.
Arguments
id
Id of HTML element / shiny input.
Returns
A unique string Id.
Get module session Id. This function rely on a shiny output object to find the right session Id.
Usage
TidyModule$getSessionId()
Returns
The Session Id of the module.
Method render()
Alias to the ui
function.
Arguments
...
arguments passed to the ui function.
Method ui()
UI function generating the module HTML elements.
This function is eventually implemented in the child module to give the module a visual representation.
Please note that a module can have many visual representations.
Arguments
...
arguments passed to ui
Method server()
server function to be overwritten and called by child module.
Usage
TidyModule$server(input, output, session, ...)
Arguments
input
shiny input.
output
shiny output.
session
shiny session.
...
extra arguments to passed to the server function.
Method view()
Preview the module in a gadget.
Arguments
...
extra arguments to passed to the server function.
Method definePort()
Function wrapper for port definition expression.
Method assignPort()
Function wrapper for port assignment expression.
Add input port function. To be called within definePort
function
Usage
TidyModule$addInputPort(
name = NULL,
description = NULL,
sample = NULL,
input = FALSE,
is_parent = FALSE,
inherit = TRUE
)
Arguments
name
port name. must be a unique input port name.
description
port description.
sample
sample dataset consumed by this port. Mandatory!
input
This argument should be ignored. Only here for backward compatibility.
is_parent
Is the port inherited from the parent module.
inherit
Should the port be passed to nested module. default to TRUE.
Function for filling an input port.
Called within the assignPort
function
Usage
TidyModule$updateInputPort(id = NULL, input = NULL)
Arguments
id
Port name or Id .
input
The reacive object.
This function add a set of input ports to the module.
Usage
TidyModule$updateInputPorts(inputs = NULL, is_parent = FALSE)
Arguments
inputs
reactivevalues with the input ports.
is_parent
Are the ports from a parent module. Default to FALSE.
Get an input port from the module.
Usage
TidyModule$getInputPort(id = 1)
Arguments
id
Name or Id of the port.
Returns
A module input port. A reactivevalues object with name, description, sample, is_parent and port elements.
Alias to the getInputPort()
function.
Arguments
id
Name or Id of the port.
Returns
A module input port. A reactivevalues object with name, description, sample, is_parent and port elements.
Get all the input ports as a reactivevalues object.
Usage
TidyModule$getInputPorts()
Returns
A reactivevalues object.
Get a input port slot.
Usage
TidyModule$getInput(id = 1, w = TRUE)
Arguments
id
Name or Id of the port.
w
boolean to enable module session check. default to TRUE.
Returns
A reactive function.
Execute an input port slot, that is, the reactive function stored in the port.
The require
argument which is TRUE
by default allows you disable checking if the port is Truthy.
See shiny::req
function.
Usage
TidyModule$execInput(id = 1, require = TRUE)
Arguments
id
Name or Id of the port.
require
Check that the port is available.
Returns
Output of the reacive function execution.
Method updateOutputPort()
Function for filling an output port.
Called within the assignPort
function
Usage
TidyModule$updateOutputPort(id = NULL, output = NULL)
Arguments
id
Port name or Id .
output
The reacive object.
Method updateOutputPorts()
This function add a set of output ports to the module.
Usage
TidyModule$updateOutputPorts(outputs = NULL, is_parent = FALSE)
Arguments
outputs
reactivevalues with the output ports.
is_parent
Are the ports from a parent module. Default to FALSE.
Method addOutputPort()
Add output port function. To be called within definePort
function
Usage
TidyModule$addOutputPort(
name = NULL,
description = NULL,
sample = NULL,
output = FALSE,
is_parent = FALSE
)
Arguments
name
port name. must be a unique output port name.
description
port description.
sample
sample dataset returned by this port. Mandatory!
output
This argument should be ignored. Only here for backward compatibility.
is_parent
Is the port inherited from the parent module.
Method getPortName()
Utility function that returns a port name from the Id.
Usage
TidyModule$getPortName(id = NULL, type = "input")
Arguments
id
Port Id
type
Port type, input or output.
Method getOutputPort()
Get an output port from the module.
Usage
TidyModule$getOutputPort(id = 1)
Arguments
id
Name or Id of the port.
Returns
A module output port. A reactivevalues object with name, description, sample, is_parent and port elements.
Alias to the getOutputPort()
function.
Arguments
id
Name or Id of the port.
Returns
A module output port. A reactivevalues object with name, description, sample, is_parent and port elements.
Method getOutputPorts()
Get all the output ports as a reactivevalues object.
Usage
TidyModule$getOutputPorts()
Returns
A reactivevalues object.
Method getOutput()
Get a output port slot.
Usage
TidyModule$getOutput(id = 1, w = TRUE)
Arguments
id
Name or Id of the port.
w
boolean to enable module session check. default to TRUE.
Returns
A reactive function.
Method execOutput()
Execute an output port slot, that is, the reactive function stored in the port.
The require
argument which is TRUE
by default allows you disable checking if the port is Truthy.
See shiny::req
function.
Usage
TidyModule$execOutput(id = 1, require = TRUE)
Arguments
id
Name or Id of the port.
require
Check that the port is available.
Returns
Output of the reacive function execution.
Method getStore()
Function for retrieving the central ModStore.
Returns
The ModStore
object.
Utility function that counts the number of input ports.
Usage
TidyModule$countInputPort()
Returns
The input ports count.
Method countOutputPort()
Utility function that counts the number of output ports.
Usage
TidyModule$countOutputPort()
Returns
The output ports count.
Alias to the callModule
function.
Arguments
...
arguments passed to the server
function of the module.
Method callModule()
callModule function. Similar to shiny callModule. Used to inject the server logic into the application.
This function don't need the user to provide a namespace Id as a module already knows its identity.
Options provided as arguments will be passed to the server function of the module.
Note that the module reference self
might not be the one injected.
Usage
TidyModule$callModule(...)
Arguments
...
arguments passed to the server
function of the module.
Method isStored()
Function to check if the module is store in the current session.
Method isGlobal()
Check if the session attached to the module is the global_session
.
Method getSession()
Get the current session.
Returns
A reactivevalues object with the following elements.
aid = application Id
path = application path
sid = session Id
count = current module count
created = session creation time
updated = session update time
collection = list of session modules
edges = list of connection edges
Method getGlobalSession()
Get the global session.
Usage
TidyModule$getGlobalSession()
Returns
A reactivevalues object with the following elements.
aid = application Id
path = application path
sid = "global_session"
count = session module count
created = session creation time
updated = session update time
collection = list of session modules
edges = empty data.frame
Method doServer()
Function interfacing with shiny's callModule.
Arguments
...
arguments passed to the server
function of the module.
Method getPortDef()
Utility function to retrieve a port definition in the form of a list.
This is a useful function to learn about a specific port.
Usage
TidyModule$getPortDef(type = NULL, id = 1)
Arguments
type
Port type, input or output.
id
Name or Id of port.
Returns
List of the port definition.
Module printing function.
Print the structure of a module.
Examples
MyModule <- R6::R6Class("MyModule", inherit = tidymodules::TidyModule)
m <- MyModule$new()
m
Method deepClone()
Module cloning function.
Take care of ports (cloning reactive objects) and nested modules.
Note that the Ids/namespace are not changed.
Usage
TidyModule$deepClone(o = NULL, i = NULL, s = NULL)
Arguments
o
Optional shiny output.
i
Optional shiny input
s
Optional shiny input
Method reset()
This function reset the ports.
Usage
TidyModule$reset(o = NULL, i = NULL, s = NULL)
Arguments
o
Optional shiny output.
i
Optional shiny input
s
Optional shiny input
Method destroy()
This function destroys the module by removing it from the ModStore
and by destroying all its observers. Please note that this function
works properly only if the observers created and used by the module are
added to self$obser
.
Usage
TidyModule$destroy(deep = FALSE)
Arguments
deep
optional logical indicating whether to destroy the
child modules as well. default to FALSE.
Method suspend()
This function suspends the module's observers.
Please note that this function works properly only if the observers
created and used by the module are added to self$obser
.
Method resume()
This function resumes the module's observers.
Please note that this function works properly only if the observers
created and used by the module are added to self$obser
.
Retrieve the shiny input.
Usage
TidyModule$getShinyInput()
Returns
Shiny input object.
Method getShinyOutput()
Retrieve the shiny output.
Usage
TidyModule$getShinyOutput()
Returns
Shiny output object.
Method getShinySession()
Retrieve the shiny output.
Usage
TidyModule$getShinySession()
Returns
Shiny session object.
Method clone()
The objects of this class are cloneable with this method.
Usage
TidyModule$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.