Neighbor highlighting via mouseover and click at the same time
1 |
#' Change
|
|
2 |
#'
|
|
3 |
#' Change nodes and edges attributes on the fly
|
|
4 |
#'
|
|
5 |
#' @param proxy An object of class \code{sigmajsProxy} as returned by \code{\link{sigmajsProxy}}.
|
|
6 |
#' @param data \code{data.frame} holding \code{delay} column.
|
|
7 |
#' @param attribute Name of attribute to change.
|
|
8 |
#' @param value Column containing value.
|
|
9 |
#' @param rate Rate at chich to refresh takes \code{once} refreshes once after all \code{values} have been changed,
|
|
10 |
#' and \code{iteration} which refreshes at every iteration.
|
|
11 |
#' @param refresh Whether to refresh the graph after the change is made.
|
|
12 |
#' @param delay Optional delay in milliseconds before change is applied. If \code{NULL} (default), no delay.
|
|
13 |
#'
|
|
14 |
#' @examples
|
|
15 |
#'
|
|
16 |
#' library(shiny)
|
|
17 |
#'
|
|
18 |
#' nodes <- sg_make_nodes()
|
|
19 |
#' nodes$new_color <- "red"
|
|
20 |
#' edges <- sg_make_edges(nodes)
|
|
21 |
#'
|
|
22 |
#' ui <- fluidPage(
|
|
23 |
#' actionButton("start", "Change color"),
|
|
24 |
#' sigmajsOutput("sg")
|
|
25 |
#' )
|
|
26 |
#'
|
|
27 |
#' server <- function(input, output){
|
|
28 |
#'
|
|
29 |
#' output$sg <- renderSigmajs({
|
|
30 |
#' sigmajs() %>%
|
|
31 |
#' sg_nodes(nodes, id, size, color) %>%
|
|
32 |
#' sg_edges(edges, id, source, target)
|
|
33 |
#' })
|
|
34 |
#'
|
|
35 |
#' observeEvent(input$start, {
|
|
36 |
#' sigmajsProxy("sg") %>% # use sigmajsProxy!
|
|
37 |
#' sg_change_nodes_p(nodes, new_color, "color")
|
|
38 |
#' })
|
|
39 |
#'
|
|
40 |
#' }
|
|
41 |
#'
|
|
42 |
#' if(interactive()) shinyApp(ui, server) # run
|
|
43 |
#'
|
|
44 |
#' @rdname change
|
|
45 |
#' @export
|
|
46 |
sg_change_nodes_p <- function(proxy, data, value, attribute, rate = c("once", "iteration"), |
|
47 |
refresh = TRUE, delay = NULL) { |
|
48 |
|
|
49 |
if (!"sigmajsProxy" %in% class(proxy)) |
|
50 |
stop("must pass sigmajsProxy object", call. = FALSE) |
|
51 |
|
|
52 |
if(missing(data) || missing(value) || missing(attribute)) |
|
53 |
stop("missing data, value, or attribute", call. = FALSE) |
|
54 |
|
|
55 |
rate <- match.arg(rate) |
|
56 |
|
|
57 |
val <- eval(substitute(value), data) |
|
58 |
|
|
59 |
message <- list(id = proxy$id, |
|
60 |
message = list(rate = rate, value = val, attribute = attribute, refresh = refresh), |
|
61 |
delay = delay) # create message |
|
62 |
|
|
63 |
proxy$session$sendCustomMessage("sg_change_nodes_p", message) |
|
64 |
|
|
65 |
return(proxy) |
|
66 |
|
|
67 |
}
|
|
68 |
|
|
69 |
#' @rdname change
|
|
70 |
#' @export
|
|
71 |
sg_change_edges_p <- function(proxy, data, value, attribute, rate = c("once", "iteration"), |
|
72 |
refresh = TRUE, delay = NULL) { |
|
73 |
|
|
74 |
if (!"sigmajsProxy" %in% class(proxy)) |
|
75 |
stop("must pass sigmajsProxy object", call. = FALSE) |
|
76 |
|
|
77 |
if(missing(data) || missing(value) || missing(attribute)) |
|
78 |
stop("missing data, value, or attribute", call. = FALSE) |
|
79 |
|
|
80 |
rate <- match.arg(rate) |
|
81 |
|
|
82 |
val <- eval(substitute(value), data) |
|
83 |
|
|
84 |
message <- list(id = proxy$id, |
|
85 |
message = list(rate = rate, value = val, attribute = attribute, refresh = refresh), |
|
86 |
delay = delay) # create message |
|
87 |
|
|
88 |
proxy$session$sendCustomMessage("sg_change_edges_p", message) |
|
89 |
|
|
90 |
return(proxy) |
|
91 |
|
|
92 |
}
|
Read our documentation on viewing source code .