TidyModule | R Documentation |
This is the main class provided by tidymodules and should be the parent of all tidymodules modules. It provides methods for defining input and output communication ports, managing module namespace and many other useful features.
id
ID of the module.
name
Name of the module as generated or provided by the user.
module_ns
Module namespace, unique identifier for the module.
parent_ns
Parent module namespace in case of nested modules.
parent_mod
Reference to parent module in case of nested modules.
pass_ports
logical value indicating if the module should pass its ports to any nested modules. This is initialized with the inherit
argument of new()
.
group
Group name of the module.
created
Initialization time of the module.
order
Initialization order.
i
reactive list of input ports.
o
reactive list of output ports.
port_names
list of input and output port names.
react
list of reactive objects used by the module.
obser
list of observers used by the module.
suspended
boolean indicating whether the module observers are suspended.
new()
Create a new tidymodules module.
TidyModule$new( id = NULL, inherit = TRUE, group = NULL, parent = NULL, collision = FALSE )
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
A new TidyModule
object.
ns()
namespace function used to generate unique Id for HTML elements.
TidyModule$ns(id)
id
Id of HTML element / shiny input.
A unique string Id.
getSessionId()
Get module session Id. This function rely on a shiny output object to find the right session Id.
TidyModule$getSessionId()
The Session Id of the module.
render()
Alias to the ui
function.
TidyModule$render(...)
...
arguments passed to the ui function.
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.
TidyModule$ui(...)
...
arguments passed to ui
Empty tagList()
server()
server function to be overwritten and called by child module.
TidyModule$server(input, output, session, ...)
input
shiny input.
output
shiny output.
session
shiny session.
...
extra arguments to passed to the server function.
view()
Preview the module in a gadget.
TidyModule$view(...)
...
extra arguments to passed to the server function.
definePort()
Function wrapper for port definition expression.
TidyModule$definePort(x)
x
expression
assignPort()
Function wrapper for port assignment expression.
TidyModule$assignPort(x)
x
expression
addInputPort()
Add input port function. To be called within definePort
function
TidyModule$addInputPort( name = NULL, description = NULL, sample = NULL, input = FALSE, is_parent = FALSE, inherit = TRUE )
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.
updateInputPort()
Function for filling an input port.
Called within the assignPort
function
TidyModule$updateInputPort(id = NULL, input = NULL)
id
Port name or Id .
input
The reacive object.
updateInputPorts()
This function add a set of input ports to the module.
TidyModule$updateInputPorts(inputs = NULL, is_parent = FALSE)
inputs
reactivevalues with the input ports.
is_parent
Are the ports from a parent module. Default to FALSE.
getInputPort()
Get an input port from the module.
TidyModule$getInputPort(id = 1)
id
Name or Id of the port.
A module input port. A reactivevalues object with name, description, sample, is_parent and port elements.
iport()
Alias to the getInputPort()
function.
TidyModule$iport(id = 1)
id
Name or Id of the port.
A module input port. A reactivevalues object with name, description, sample, is_parent and port elements.
getInputPorts()
Get all the input ports as a reactivevalues object.
TidyModule$getInputPorts()
A reactivevalues object.
getInput()
Get a input port slot.
TidyModule$getInput(id = 1, w = TRUE)
id
Name or Id of the port.
w
boolean to enable module session check. default to TRUE.
A reactive function.
execInput()
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.
TidyModule$execInput(id = 1, require = TRUE)
id
Name or Id of the port.
require
Check that the port is available.
Output of the reacive function execution.
updateOutputPort()
Function for filling an output port.
Called within the assignPort
function
TidyModule$updateOutputPort(id = NULL, output = NULL)
id
Port name or Id .
output
The reacive object.
updateOutputPorts()
This function add a set of output ports to the module.
TidyModule$updateOutputPorts(outputs = NULL, is_parent = FALSE)
outputs
reactivevalues with the output ports.
is_parent
Are the ports from a parent module. Default to FALSE.
addOutputPort()
Add output port function. To be called within definePort
function
TidyModule$addOutputPort( name = NULL, description = NULL, sample = NULL, output = FALSE, is_parent = FALSE )
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.
getPortName()
Utility function that returns a port name from the Id.
TidyModule$getPortName(id = NULL, type = "input")
id
Port Id
type
Port type, input or output.
Port name.
getOutputPort()
Get an output port from the module.
TidyModule$getOutputPort(id = 1)
id
Name or Id of the port.
A module output port. A reactivevalues object with name, description, sample, is_parent and port elements.
oport()
Alias to the getOutputPort()
function.
TidyModule$oport(id = 1)
id
Name or Id of the port.
A module output port. A reactivevalues object with name, description, sample, is_parent and port elements.
getOutputPorts()
Get all the output ports as a reactivevalues object.
TidyModule$getOutputPorts()
A reactivevalues object.
getOutput()
Get a output port slot.
TidyModule$getOutput(id = 1, w = TRUE)
id
Name or Id of the port.
w
boolean to enable module session check. default to TRUE.
A reactive function.
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.
TidyModule$execOutput(id = 1, require = TRUE)
id
Name or Id of the port.
require
Check that the port is available.
Output of the reacive function execution.
getStore()
Function for retrieving the central ModStore.
TidyModule$getStore()
The ModStore
object.
countInputPort()
Utility function that counts the number of input ports.
TidyModule$countInputPort()
The input ports count.
countOutputPort()
Utility function that counts the number of output ports.
TidyModule$countOutputPort()
The output ports count.
use()
Alias to the callModule
function.
TidyModule$use(...)
...
arguments passed to the server
function of the module.
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.
TidyModule$callModule(...)
...
arguments passed to the server
function of the module.
isStored()
Function to check if the module is store in the current session.
TidyModule$isStored()
logical value.
isGlobal()
Check if the session attached to the module is the global_session
.
TidyModule$isGlobal()
logical value.
getSession()
Get the current session.
TidyModule$getSession()
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
getGlobalSession()
Get the global session.
TidyModule$getGlobalSession()
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
doServer()
Function interfacing with shiny's callModule.
TidyModule$doServer(...)
...
arguments passed to the server
function of the module.
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.
TidyModule$getPortDef(type = NULL, id = 1)
type
Port type, input or output.
id
Name or Id of port.
List of the port definition.
print()
Module printing function. Print the structure of a module.
TidyModule$print()
MyModule <- R6::R6Class("MyModule", inherit = tidymodules::TidyModule) m <- MyModule$new() m
deepClone()
Module cloning function. Take care of ports (cloning reactive objects) and nested modules. Note that the Ids/namespace are not changed.
TidyModule$deepClone(o = NULL, i = NULL, s = NULL)
o
Optional shiny output.
i
Optional shiny input
s
Optional shiny input
A cloned module.
reset()
This function reset the ports.
TidyModule$reset(o = NULL, i = NULL, s = NULL)
o
Optional shiny output.
i
Optional shiny input
s
Optional shiny input
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
.
TidyModule$destroy(deep = FALSE)
deep
optional logical indicating whether to destroy the child modules as well. default to FALSE.
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
.
TidyModule$suspend()
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
.
TidyModule$resume()
getShinyInput()
Retrieve the shiny input.
TidyModule$getShinyInput()
Shiny input object.
getShinyOutput()
Retrieve the shiny output.
TidyModule$getShinyOutput()
Shiny output object.
getShinySession()
Retrieve the shiny output.
TidyModule$getShinySession()
Shiny session object.
clone()
The objects of this class are cloneable with this method.
TidyModule$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `TidyModule$print` ## ------------------------------------------------ MyModule <- R6::R6Class("MyModule", inherit = tidymodules::TidyModule) m <- MyModule$new() m
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.