19 |
19 |
|
#' Markdown documents, and within Shiny output bindings. |
20 |
20 |
|
#' |
21 |
21 |
|
#' @examples |
22 |
|
- |
#' \dontrun{ |
|
22 |
+ |
#' \donttest{ |
23 |
23 |
|
#' # Create a simple graph running left to right (note |
24 |
24 |
|
#' # that the whitespace is not important) |
25 |
|
- |
#' DiagrammeR(" |
26 |
|
- |
#' graph LR |
27 |
|
- |
#' A-->B |
28 |
|
- |
#' A-->C |
29 |
|
- |
#' C-->E |
30 |
|
- |
#' B-->D |
31 |
|
- |
#' C-->D |
32 |
|
- |
#' D-->F |
33 |
|
- |
#' E-->F |
34 |
|
- |
#' ") |
|
25 |
+ |
#' # DiagrammeR(" |
|
26 |
+ |
#' # graph LR |
|
27 |
+ |
#' # A-->B |
|
28 |
+ |
#' # A-->C |
|
29 |
+ |
#' # C-->E |
|
30 |
+ |
#' # B-->D |
|
31 |
+ |
#' # C-->D |
|
32 |
+ |
#' # D-->F |
|
33 |
+ |
#' # E-->F |
|
34 |
+ |
#' # ") |
|
35 |
+ |
#' |
35 |
36 |
|
#' # Create the equivalent graph but have it running |
36 |
37 |
|
#' # from top to bottom |
37 |
|
- |
#' DiagrammeR(" |
38 |
|
- |
#' graph TB |
39 |
|
- |
#' A-->B |
40 |
|
- |
#' A-->C |
41 |
|
- |
#' C-->E |
42 |
|
- |
#' B-->D |
43 |
|
- |
#' C-->D |
44 |
|
- |
#' D-->F |
45 |
|
- |
#' E-->F |
46 |
|
- |
#' ") |
|
38 |
+ |
#' # DiagrammeR(" |
|
39 |
+ |
#' # graph TB |
|
40 |
+ |
#' # A-->B |
|
41 |
+ |
#' # A-->C |
|
42 |
+ |
#' # C-->E |
|
43 |
+ |
#' # B-->D |
|
44 |
+ |
#' # C-->D |
|
45 |
+ |
#' # D-->F |
|
46 |
+ |
#' # E-->F |
|
47 |
+ |
#' # ") |
47 |
48 |
|
#' |
48 |
49 |
|
#' # Create a graph with different node shapes and |
49 |
50 |
|
#' # provide fill styles for each node |
50 |
|
- |
#' DiagrammeR("graph LR;A(Rounded)-->B[Squared];B-->C{A Decision}; |
51 |
|
- |
#' C-->D[Square One];C-->E[Square Two]; |
52 |
|
- |
#' style A fill:#E5E25F; style B fill:#87AB51; style C fill:#3C8937; |
53 |
|
- |
#' style D fill:#23772C; style E fill:#B6E6E6;" |
54 |
|
- |
#' ) |
|
51 |
+ |
#' # DiagrammeR("graph LR;A(Rounded)-->B[Squared];B-->C{A Decision}; |
|
52 |
+ |
#' # C-->D[Square One];C-->E[Square Two]; |
|
53 |
+ |
#' # style A fill:#E5E25F; style B fill:#87AB51; style C fill:#3C8937; |
|
54 |
+ |
#' # style D fill:#23772C; style E fill:#B6E6E6;" |
|
55 |
+ |
#' # ) |
55 |
56 |
|
#' |
56 |
57 |
|
#' # Load in the 'mtcars' dataset |
57 |
|
- |
#' data(mtcars) |
58 |
|
- |
#' connections <- sapply( |
59 |
|
- |
#' 1:ncol(mtcars) |
60 |
|
- |
#' ,function(i) { |
61 |
|
- |
#' paste0( |
62 |
|
- |
#' i |
63 |
|
- |
#' ,"(",colnames(mtcars)[i],")---" |
64 |
|
- |
#' ,i,"-stats(" |
65 |
|
- |
#' ,paste0( |
66 |
|
- |
#' names(summary(mtcars[,i])) |
67 |
|
- |
#' ,": " |
68 |
|
- |
#' ,unname(summary(mtcars[,i])) |
69 |
|
- |
#' ,collapse="<br/>" |
70 |
|
- |
#' ) |
71 |
|
- |
#' ,")" |
72 |
|
- |
#' ) |
73 |
|
- |
#' } |
74 |
|
- |
#' ) |
|
58 |
+ |
#' # data(mtcars) |
|
59 |
+ |
#' # connections <- sapply( |
|
60 |
+ |
#' # 1:ncol(mtcars) |
|
61 |
+ |
#' # ,function(i) { |
|
62 |
+ |
#' # paste0( |
|
63 |
+ |
#' # i |
|
64 |
+ |
#' # ,"(",colnames(mtcars)[i],")---" |
|
65 |
+ |
#' # ,i,"-stats(" |
|
66 |
+ |
#' # ,paste0( |
|
67 |
+ |
#' # names(summary(mtcars[,i])) |
|
68 |
+ |
#' # ,": " |
|
69 |
+ |
#' # ,unname(summary(mtcars[,i])) |
|
70 |
+ |
#' # ,collapse="<br/>" |
|
71 |
+ |
#' # ) |
|
72 |
+ |
#' # ,")" |
|
73 |
+ |
#' # ) |
|
74 |
+ |
#' # } |
|
75 |
+ |
#' # ) |
75 |
76 |
|
#' |
76 |
77 |
|
#' # Create a diagram using the 'connections' object |
77 |
|
- |
#' DiagrammeR( |
78 |
|
- |
#' paste0( |
79 |
|
- |
#' "graph TD;", "\n", |
80 |
|
- |
#' paste(connections, collapse = "\n"),"\n", |
81 |
|
- |
#' "classDef column fill:#0001CC, stroke:#0D3FF3, stroke-width:1px;" ,"\n", |
82 |
|
- |
#' "class ", paste0(1:length(connections), collapse = ","), " column;" |
83 |
|
- |
#' ) |
84 |
|
- |
#' ) |
|
78 |
+ |
#' # DiagrammeR( |
|
79 |
+ |
#' # paste0( |
|
80 |
+ |
#' # "graph TD;", "\n", |
|
81 |
+ |
#' # paste(connections, collapse = "\n"),"\n", |
|
82 |
+ |
#' # "classDef column fill:#0001CC, stroke:#0D3FF3, stroke-width:1px;" ,"\n", |
|
83 |
+ |
#' # "class ", paste0(1:length(connections), collapse = ","), " column;" |
|
84 |
+ |
#' # ) |
|
85 |
+ |
#' # ) |
85 |
86 |
|
#' |
86 |
87 |
|
#' # Also with `DiagrammeR()`, you can use tags |
87 |
88 |
|
#' # from `htmltools` (just make sure to use |
88 |
89 |
|
#' # `class = "mermaid"`) |
89 |
90 |
|
#' library(htmltools) |
90 |
|
- |
#' diagramSpec = " |
91 |
|
- |
#' graph LR; |
92 |
|
- |
#' id1(Start)-->id2(Stop); |
93 |
|
- |
#' style id1 fill:#f9f,stroke:#333,stroke-width:4px; |
94 |
|
- |
#' style id2 fill:#ccf,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5; |
95 |
|
- |
#' " |
96 |
|
- |
#' html_print(tagList( |
97 |
|
- |
#' tags$h1("R + mermaid.js = Something Special") |
98 |
|
- |
#' ,tags$pre(diagramSpec) |
99 |
|
- |
#' ,tags$div(class="mermaid",diagramSpec) |
100 |
|
- |
#' ,DiagrammeR() |
101 |
|
- |
#' )) |
|
91 |
+ |
#' # diagramSpec = " |
|
92 |
+ |
#' # graph LR; |
|
93 |
+ |
#' # id1(Start)-->id2(Stop); |
|
94 |
+ |
#' # style id1 fill:#f9f,stroke:#333,stroke-width:4px; |
|
95 |
+ |
#' # style id2 fill:#ccf,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5; |
|
96 |
+ |
#' # " |
|
97 |
+ |
#' # html_print(tagList( |
|
98 |
+ |
#' # tags$h1("R + mermaid.js = Something Special") |
|
99 |
+ |
#' # ,tags$pre(diagramSpec) |
|
100 |
+ |
#' # ,tags$div(class="mermaid", diagramSpec) |
|
101 |
+ |
#' # ,DiagrammeR() |
|
102 |
+ |
#' # )) |
102 |
103 |
|
#' |
103 |
104 |
|
#' # Create a sequence diagram |
104 |
|
- |
#' DiagrammeR(" |
105 |
|
- |
#' sequenceDiagram; |
106 |
|
- |
#' customer->>ticket seller: ask for a ticket; |
107 |
|
- |
#' ticket seller->>database: seats; |
108 |
|
- |
#' alt tickets available |
109 |
|
- |
#' database->>ticket seller: ok; |
110 |
|
- |
#' ticket seller->>customer: confirm; |
111 |
|
- |
#' customer->>ticket seller: ok; |
112 |
|
- |
#' ticket seller->>database: book a seat; |
113 |
|
- |
#' ticket seller->>printer: print a ticket; |
114 |
|
- |
#' else sold out |
115 |
|
- |
#' database->>ticket seller: none left; |
116 |
|
- |
#' ticket seller->>customer: sorry; |
117 |
|
- |
#' end |
118 |
|
- |
#' ") |
|
105 |
+ |
#' # DiagrammeR(" |
|
106 |
+ |
#' # sequenceDiagram; |
|
107 |
+ |
#' # customer->>ticket seller: ask for a ticket; |
|
108 |
+ |
#' # ticket seller->>database: seats; |
|
109 |
+ |
#' # alt tickets available |
|
110 |
+ |
#' # database->>ticket seller: ok; |
|
111 |
+ |
#' # ticket seller->>customer: confirm; |
|
112 |
+ |
#' # customer->>ticket seller: ok; |
|
113 |
+ |
#' # ticket seller->>database: book a seat; |
|
114 |
+ |
#' # ticket seller->>printer: print a ticket; |
|
115 |
+ |
#' # else sold out |
|
116 |
+ |
#' # database->>ticket seller: none left; |
|
117 |
+ |
#' # ticket seller->>customer: sorry; |
|
118 |
+ |
#' # end |
|
119 |
+ |
#' # ") |
119 |
120 |
|
#' } |
120 |
121 |
|
#' |
121 |
122 |
|
#' @import htmlwidgets |
5644261
681f564
f53b20c