Events

Add javascript event with visEvents()

nodes <- data.frame(id = 1:3, label = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3))

visNetwork(nodes, edges) %>%
 visEvents(selectNode = "function(properties) {
      alert('selected nodes ' + this.body.data.nodes.get(properties.nodes[0]).id);}")

Export

Since visNetwork_0.2.1, you can use visSave() for save network in .html file, and visExport() to save as .png with shiny :

network <- visNetwork(nodes, edges, width = "100%")
network %>% visSave(file = "network.html")
# same as
visSave(network, file = "network.html")
# or
htmlwidgets::saveWidget(network, "network.html")

Use DOT language data

visNetwork(dot = 'dinetwork {1 -> 1 -> 2; 2 -> 3; 2 -- 4; 2 -> 1 }', 
           width = "100%")

Use gephi json export file

# don't run here
visNetwork(gephi = 'WorldCup2014.json')

Clustering

Some first (experimental) functions are available :

  • visClusteringByColor()
  • visClusteringByConnection()
  • visClusteringByHubsize()
  • visClusteringByGroup()
  • visClusteringOutliers()

You can open clusters by double-clicking, and re-cluster with button.

nodes <- data.frame(id = 1:10, label = paste("Label", 1:10), 
   group = sample(c("A", "B"), 10, replace = TRUE))

edges <- data.frame(from = c(2,5,10), to = c(1,2,10))

visNetwork(nodes, edges, height = "400px", width = "100%") %>%
  visGroups(groupname = "A", color = "red", shape = "square") %>%
  visGroups(groupname = "B", color = "yellow", shape = "triangle") %>%
  visClusteringByColor(colors = c("red")) %>%
  visClusteringByGroup(groups = c("B")) %>%
  visLegend()

© 2016-2017 DataStorm

Fork me on GitHub