Node: Store the session object of modules

Description Usage Format Details Usage Methods Examples

Description

Use nodes to store the session objects of all modules in a shiny app in a tree-like data-structure. A node object is an instantiation of the R6Class 'node'.

Usage

1

Format

An object of class R6ClassGenerator of length 24.

Details

Instantiate a new node with node$new(name, parent, session). Passing the arguments name and session is mandatory. The root or entry node to a tree obviously has no parent.

Usage

1
node <- Node$new(name, parent, session)

Methods

new(name, parent, session)

Initialize the node. Arguments name and session are mandatory.

name Character. Node's name.
parent A Node object.
session A Session object.
add_child(child)

Add a child to the node. You usually don't need to call this function.

child A Node object.
child(path_to_child)

Get a child of the node determined by the character vector path_to_child. If there is a node in with the name of the first element of path_to_child, child() looks in the children of this node for an child node with the name of the second element of path_to_child and so on and returns the last child found. Calling this method without arguments has the same effect as

children_names()

Returns the names of all children nodes as a character vector.

create_list()

Returns a list representing all child and child-child nodes.

get(what)

Returns the private field or method with the name what.

sibling(name)

Returns the sibling node with name name. Calling this method without arguments returns the names of all siblings.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## Not run: 
  # Entry point of shiny app
  server <- function(input, output, session) {
    # root node has no parent
    self <- node$new("root", session = session)

    shiny::callModule(module, "id_module", parent = self)
  }

  # Module server function
  module <- function(input, output, session, parent) {
    self <- node$new("module", parent, session)

    shiny::callModule(module, "id_module", parent = self)
  }

  module_2 <- function(input, output, session, parent) {
    # Children can have the same name as their parent
    self <- node$new("module", parent, session)
  }

## End(Not run)

# Instantiate nodes
root <- node$new("root", session = "session")
branch_1 <- node$new("branch_1", root, "session")
branch_2 <- node$new("branch_2", root, "session")
leave <- node$new("leave", branch_1, "session")

# Returns leave node
root$child(c("branch_1", "leave"))

# Returns branch_2 node
branch_1$sibling(branch_1$sibling()[[1]])
leave$get("parent")$sibling("branch_2")
leave$get("parent")$get("parent")$child("branch_2")

DavidBarke/QWUtils documentation built on Jan. 13, 2020, 11:52 a.m.