read: Read

Description Usage Arguments Value Functions Examples

Description

Read nodes and edges to add to the graph. Other proxy methods to add data to a graph have to add nodes and edges one by one, thereby draining the browser, this method will add multiple nodes and edges more efficiently.

Usage

1
2
3
4
5

Arguments

proxy

An object of class sigmajsProxy as returned by sigmajsProxy.

data

A data.frame of _one_ node or edge.

...

any column.

Value

The proxy object.

Functions

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
37
38
39
40
41
42
43
44
library(shiny)

ui <- fluidPage(
	actionButton("add", "add nodes & edges"),
	sigmajsOutput("sg")
)

server <- function(input, output, session){

	nodes <- sg_make_nodes()
	edges <- sg_make_edges(nodes)

	output$sg <- renderSigmajs({
		sigmajs() %>% 
			sg_nodes(nodes, id, label, color, size) %>% 
			sg_edges(edges, id, source, target) %>% 
			sg_layout()
	})

	i <- 10

	observeEvent(input$add, {
		new_nodes <- sg_make_nodes()
		new_nodes$id <- as.character(as.numeric(new_nodes$id) + i)
		i <<- i + 10
		ids <- 1:(i)
		new_edges <- data.frame(
			id = as.character((i * 2 + 15):(i * 2 + 29)),
			source = as.character(sample(ids, 15)),
			target = as.character(sample(ids, 15))
		)
		
		sigmajsProxy("sg") %>% 
			sg_force_kill_p() %>% 
			sg_read_nodes_p(new_nodes, id, label, color, size) %>% 
			sg_read_edges_p(new_edges, id, source, target) %>% 
			sg_read_exec_p() %>% 
			sg_force_start_p() %>% 
			sg_refresh_p()
	})

}

if(interactive()) shinyApp(ui, server)

sigmajs documentation built on July 8, 2020, 5:16 p.m.