rich-iannone / DiagrammeR

@@ -19,103 +19,104 @@
Loading
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
@@ -157,5 +158,6 @@
Loading
157 158
    x = x,
158 159
    width = width,
159 160
    height = height,
160 -
    package = "DiagrammeR")
161 +
    package = "DiagrammeR"
162 +
  )
161 163
}

@@ -58,7 +58,9 @@
Loading
58 58
      diagram = diagram,
59 59
      config = list(
60 60
        engine = engine,
61 -
        options = options))
61 +
        options = options
62 +
      )
63 +
    )
62 64
63 65
  # Only use the Viewer for newer versions of RStudio,
64 66
  # but allow other, non-RStudio viewers
@@ -73,7 +75,8 @@
Loading
73 75
    width = width,
74 76
    height = height,
75 77
    package = "DiagrammeR",
76 -
    htmlwidgets::sizingPolicy(viewer.suppress = viewer.suppress))
78 +
    htmlwidgets::sizingPolicy(viewer.suppress = viewer.suppress)
79 +
  )
77 80
}
78 81
79 82
#' Widget output function for use in Shiny
@@ -83,45 +86,19 @@
Loading
83 86
#'   coerced to a string and have `px` appended.
84 87
#' @param height A valid CSS unit for the height or a number, which will be
85 88
#'   coerced to a string and have `px` appended.
86 -
#' @examples
87 -
#' \dontrun{
88 -
#' library(shiny)
89 -
#' library(shinyAce)
90 -
#'
91 -
#' ui = shinyUI(fluidPage(fluidRow(
92 -
#'   column(
93 -
#'     width=4
94 -
#'     , aceEditor("ace", selectionId = "selection", value="digraph {A;}")
95 -
#'   ),
96 -
#'   column(
97 -
#'     width = 6
98 -
#'     , grVizOutput('diagram' )
99 -
#'   )
100 -
#' )))
101 -
#'
102 -
#' server = function(input, output) {
103 -
#'   output$diagram <- renderGrViz({
104 -
#'     grViz(
105 -
#'       input$ace
106 -
#'     )
107 -
#'   })
108 -
#'
109 -
#' }
110 -
#'
111 -
#' shinyApp(ui = ui, server = server)
112 -
#' }
113 89
#'
114 90
#' @export
115 91
grVizOutput <- function(outputId,
116 -
                        width = '100%',
117 -
                        height = '400px') {
92 +
                        width = "100%",
93 +
                        height = "400px") {
118 94
119 -
  shinyWidgetOutput(
95 +
  htmlwidgets::shinyWidgetOutput(
120 96
    outputId = outputId,
121 -
    'grViz',
122 -
    width,
123 -
    height,
124 -
    package = 'DiagrammeR')
97 +
    name = "grViz",
98 +
    width = width,
99 +
    height = height,
100 +
    package = "DiagrammeR"
101 +
  )
125 102
}
126 103
127 104
#' Widget render function for use in Shiny
@@ -138,11 +115,12 @@
Loading
138 115
139 116
  if (!quoted) expr <- substitute(expr)
140 117
141 -
  shinyRenderWidget(
142 -
    expr,
143 -
    grVizOutput,
144 -
    env,
145 -
    quoted = TRUE)
118 +
  htmlwidgets::shinyRenderWidget(
119 +
    expr = expr,
120 +
    outputFunction = grVizOutput,
121 +
    evn = env,
122 +
    quoted = TRUE
123 +
  )
146 124
}
147 125
148 126
#' Add MathJax-formatted equation text

@@ -19,15 +19,17 @@
Loading
19 19
#'
20 20
#' # Save the graph to disk; use
21 21
#' # the file name `gnp_graph.dgr`
22 -
#' save_graph(
23 -
#'   x = gnp_graph,
24 -
#'   file = "gnp_graph")
22 +
#' # save_graph(
23 +
#' #   x = gnp_graph,
24 +
#' #   file = "gnp_graph"
25 +
#' # )
25 26
#'
26 27
#' # To read the graph file from
27 28
#' # disk, use `open_graph()`
28 -
#' gnp_graph_2 <-
29 -
#'   open_graph(
30 -
#'     file = "gnp_graph.dgr")
29 +
#' # gnp_graph_2 <-
30 +
#' #   open_graph(
31 +
#' #     file = "gnp_graph.dgr"
32 +
#' # )
31 33
#'
32 34
#' @export
33 35
save_graph <- function(x,

@@ -4,7 +4,7 @@
Loading
4 4
#'
5 5
#' @inheritParams render_graph
6 6
#' @examples
7 -
#' \dontrun{
7 +
#'
8 8
#' # Create a node data frame (ndf)
9 9
#' ndf <-
10 10
#'   create_node_df(
@@ -14,7 +14,8 @@
Loading
14 14
#'                   "pink", "aqua", "yellow"),
15 15
#'     shape = "dot",
16 16
#'     size = c(20, 80, 40, 10, 30, 50),
17 -
#'     type = c("1", "1", "1", "2", "2", "2"))
17 +
#'     type = c("1", "1", "1", "2", "2", "2")
18 +
#'   )
18 19
#'
19 20
#' # Create an edge data frame (edf)
20 21
#' edf <-
@@ -23,16 +24,17 @@
Loading
23 24
#'     to = c(4, 3, 1, 3, 1, 4),
24 25
#'     color = c("green", "green", "grey",
25 26
#'               "grey", "blue", "blue"),
26 -
#'     rel = "leading_to")
27 +
#'     rel = "leading_to"
28 +
#'   )
27 29
#'
28 30
#' # Create a graph object
29 31
#' graph <-
30 32
#'   create_graph(
31 33
#'     nodes_df = ndf,
32 -
#'     edges_df = edf)
34 +
#'     edges_df = edf
35 +
#'   )
33 36
#'
34 -
#' visnetwork(graph)
35 -
#' }
37 +
#' # visnetwork(graph)
36 38
#'
37 39
#' @import visNetwork
38 40
#' @export

@@ -16,7 +16,7 @@
Loading
16 16
#' @param height An optional parameter for specifying the height of the
17 17
#'   resulting graphic in pixels.
18 18
#' @examples
19 -
#' \dontrun{
19 +
#' \donttest{
20 20
#' # Render a graph that's a
21 21
#' # balanced tree
22 22
#' create_graph() %>%

@@ -36,7 +36,8 @@
Loading
36 36
#' graph <-
37 37
#'   create_graph() %>%
38 38
#'   add_full_graph(
39 -
#'     n = 3, keep_loops = TRUE)
39 +
#'     n = 3, keep_loops = TRUE
40 +
#'   )
40 41
#'
41 42
#' # Get node information
42 43
#' # from this graph
@@ -58,7 +59,8 @@
Loading
58 59
#'     n = 3,
59 60
#'     type = "connected",
60 61
#'     label = c("1st", "2nd", "3rd"),
61 -
#'     rel = "connected_to")
62 +
#'     rel = "connected_to"
63 +
#'   )
62 64
#'
63 65
#' # Show the graph's node
64 66
#' # data frame (ndf)
@@ -82,9 +84,10 @@
Loading
82 84
#'   sample(9, FALSE) %>%
83 85
#'   round(2) %>%
84 86
#'   matrix(
85 -
#'     nc = 3,
86 -
#'     nr = 3,
87 -
#'     dimnames = list(c("a", "b", "c")))
87 +
#'     ncol = 3,
88 +
#'     nrow = 3,
89 +
#'     dimnames = list(c("a", "b", "c"))
90 +
#'   )
88 91
#'
89 92
#' # Create the fully-connected
90 93
#' # graph (without loops however)
@@ -118,7 +121,8 @@
Loading
118 121
#'     label = TRUE,
119 122
#'     rel = "related_to",
120 123
#'     edge_wt_matrix = edge_wt_matrix,
121 -
#'     keep_loops = FALSE) %>%
124 +
#'     keep_loops = FALSE
125 +
#'   ) %>%
122 126
#'   get_edge_df()
123 127
#'
124 128
#' @export

@@ -12,7 +12,6 @@
Loading
12 12
#'   condition of being a property graph, otherwise the function yields an
13 13
#'   error.
14 14
#' @examples
15 -
#' \dontrun{
16 15
#' # Create a randomized property
17 16
#' # graph with 1000 nodes and 1350 edges
18 17
#' property_graph <-
@@ -73,8 +72,7 @@
Loading
73 72
#' # Display this graph's
74 73
#' # metagraph, or, the underlying
75 74
#' # graph model for a property graph
76 -
#' display_metagraph(property_graph)
77 -
#' }
75 +
#' # display_metagraph(property_graph)
78 76
#'
79 77
#' @export
80 78
display_metagraph <- function(graph) {

@@ -18,10 +18,12 @@
Loading
18 18
#' @examples
19 19
#' # Create an adjacency matrix
20 20
#' adj_matrix <-
21 -
#'   sample(0:1, 100,
22 -
#'          replace = TRUE,
23 -
#'          prob = c(0.9,0.1)) %>%
24 -
#'   matrix(nc = 10)
21 +
#'   sample(
22 +
#'     0:1, 100,
23 +
#'     replace = TRUE,
24 +
#'     prob = c(0.9,0.1)
25 +
#'   ) %>%
26 +
#'   matrix(ncol = 10)
25 27
#'
26 28
#' # Create a graph from the adjacency matrix
27 29
#' graph <- from_adj_matrix(adj_matrix)
Files Coverage
R 81.45%
Project Totals (244 files) 81.45%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading