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.

Public fields

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.

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.

Usage

TidyModule$ns(id)

Arguments

id

Id of HTML element / shiny input.

Returns

A unique string Id.


Method getSessionId()

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.

Usage

TidyModule$render(...)

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.

Usage

TidyModule$ui(...)

Arguments

...

arguments passed to ui

Returns

Empty tagList()


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.

Usage

TidyModule$view(...)

Arguments

...

extra arguments to passed to the server function.


Method definePort()

Function wrapper for port definition expression.

Usage

TidyModule$definePort(x)

Arguments

x

expression


Method assignPort()

Function wrapper for port assignment expression.

Usage

TidyModule$assignPort(x)

Arguments

x

expression


Method addInputPort()

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.


Method updateInputPort()

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.


Method updateInputPorts()

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.


Method getInputPort()

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.


Method iport()

Alias to the getInputPort() function.

Usage

TidyModule$iport(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.


Method getInputPorts()

Get all the input ports as a reactivevalues object.

Usage

TidyModule$getInputPorts()

Returns

A reactivevalues object.


Method getInput()

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.


Method 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.

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.

Returns

Port name.


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.


Method oport()

Alias to the getOutputPort() function.

Usage

TidyModule$oport(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.


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.

Usage

TidyModule$getStore()

Returns

The ModStore object.


Method countInputPort()

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.


Method use()

Alias to the callModule function.

Usage

TidyModule$use(...)

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.

Usage

TidyModule$isStored()

Returns

logical value.


Method isGlobal()

Check if the session attached to the module is the global_session.

Usage

TidyModule$isGlobal()

Returns

logical value.


Method getSession()

Get the current session.

Usage

TidyModule$getSession()

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.

Usage

TidyModule$doServer(...)

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.


Method print()

Module printing function. Print the structure of a module.

Usage

TidyModule$print()

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

Returns

A cloned module.


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.

Usage

TidyModule$suspend()


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.

Usage

TidyModule$resume()


Method getShinyInput()

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.

Examples


## ------------------------------------------------
## Method `TidyModule$print`
## ------------------------------------------------

MyModule <- R6::R6Class("MyModule", inherit = tidymodules::TidyModule)
m <- MyModule$new()
m
#> Module Namespace MyModule-3
#> Module Session global_session
#> - Class MyModule << TidyModule << R6
#> - Input [0]
#> - Output [0]