sigmajs lets you add buttons to trigger events, in static documents.

A button to export the graph as SVG, not that you can export to an image (png, jpeg, gif or tiff).

You can also trigger mutliple events with the button by passing a vector of events to event. Below we add a button that will start the forceAtlas2 layout and stop it after 3 seconds.


Since version 1.1.2 you can add multiple buttons.

# initial nodes
nodes <- sg_make_nodes()

# additional nodes
nodes2 <- sg_make_nodes()
nodes2$id <- as.character(seq(11, 20))

# add delay
nodes2$delay <- runif(nrow(nodes2), 500, 1000)
nodes2$text <- seq.Date(Sys.Date(), Sys.Date() + 9, "days")

sigmajs() %>%
  sg_nodes(nodes, id, label, size, color) %>%
  sg_add_nodes(nodes2, delay, id, label, size, color) %>% 
  sg_progress(nodes2, delay, text, tag = tags$h3) %>%
  sg_force() %>% 
  sg_button(c("add_nodes", "progress"), "add", tag = tags$a, position = "bottom") %>% 
  sg_button("force_start", "force", tag = tags$a, position = "bottom")

add force

Events that can be triggered via a button (corresponding function name minus sg_):

  • force_start
  • force_stop
  • noverlap
  • drag_nodes
  • relative_size
  • add_nodes
  • add_edges
  • add_nodes_edges
  • drop_nodes
  • drop_edges
  • animate
  • export_svg
  • export_img
  • progress

You will examples of the above scattered throughout the documentation.