-
Notifications
You must be signed in to change notification settings - Fork 5
/
Build-Many-Element-With-Data-frame.Rmd
54 lines (41 loc) · 1.09 KB
/
Build-Many-Element-With-Data-frame.Rmd
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
45
46
47
48
49
50
51
52
53
54
---
title: "Build Many Element With data.frame"
---
If small amount of nodes / edges are needed to be plotted, using `buildNode` and `buildEdge` will fine. However in most case, almost ~ 100 element or more should be plotted.
Which is not efficient with repetitive using of `buildNode` and `buildEdge`.
`buildElem` is function for that case, which build uniform elements(only `node` or only `edge`).
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup}
library(shinyCyJS)
```
These 2 code will return same results. (never mind layout, it contains randomness)
```{r}
shinyCyJS(list(
buildNode("a"),
buildNode("b", width = 20),
buildNode("c", width = 30),
buildNode("d", width = 40),
buildEdge("a", "b"),
buildEdge("a", "c"),
buildEdge("c", "d"),
buildEdge("b", "d")
))
```
```{r}
a <- data.frame(
id = c("a", "b", "c", "d"),
width = c(15, 20, 30, 40)
)
b <- data.frame(
source = c("a", "a", "c", "b"),
target = c("b", "c", "d", "d")
)
nodes <- buildElems(a, "Node")
edges <- buildElems(b, "Edge")
shinyCyJS(c(nodes, edges))
```