1
#' Get nodes
2
#'
3
#' Retrieve nodes and edges from the widget.
4
#'
5
#' @param proxy An object of class \code{sigmajsProxy} as returned by \code{\link{sigmajsProxy}}.
6
#'
7
#' @examples
8
#' library(shiny)
9
#' 
10
#' nodes <- sg_make_nodes()
11
#' edges <- sg_make_edges(nodes)
12
#' 
13
#' ui <- fluidPage(
14
#'   actionButton("start", "Trigger layout"), # add the button
15
#'   sigmajsOutput("sg"),
16
#'   verbatimTextOutput("txt")
17
#' ) 
18
#' 
19
#' server <- function(input, output){
20
#' 
21
#'   output$sg <- renderSigmajs({
22
#'     sigmajs() %>%
23
#'       sg_nodes(nodes, id, size, color) %>%
24
#'       sg_edges(edges, id, source, target)
25
#'   })
26
#' 
27
#'   observeEvent(input$start, {
28
#'     sigmajsProxy("sg") %>% # use sigmajsProxy!
29
#'       sg_get_nodes_p()
30
#'   })
31
#' 
32
#'   output$txt <- renderPrint({
33
#'     input$sg_nodes
34
#'   })
35
#' 
36
#' }
37
#' if(interactive()) shinyApp(ui, server) # run
38
#' 
39
#' @return The \code{proxy} object.
40
#' 
41
#' @rdname get_graph
42
#' @export
43
sg_get_nodes_p <- function(proxy) {
44

45 0
  if (missing(proxy))
46 0
    stop("must pass proxy", call. = FALSE)
47
  
48 0
  .test_proxy(proxy)
49

50 0
	message <- list(id = proxy$id)
51

52 0
	proxy$session$sendCustomMessage("sg_get_nodes_p", message)
53 0
  return(proxy)
54
}
55

56
#' @rdname get_graph
57
#' @export
58
sg_get_edges_p <- function(proxy) {
59

60 0
  if (missing(proxy))
61 0
    stop("must pass proxy", call. = FALSE)
62
  
63 0
  .test_proxy(proxy)
64

65 0
	message <- list(id = proxy$id)
66

67 0
	proxy$session$sendCustomMessage("sg_get_edges_p", message)
68 0
  return(proxy)
69
}

Read our documentation on viewing source code .

Loading