0

I am trying to build interactive network visualizations of objects that are linked. I have reviewed the code at: https://christophergandrud.github.io/networkD3/

but was not able to locate a code sample that would help me to convert Nodes into clickable urls that would redirect user or would launch a new browser window. Is this possible? My question relates to the networkD3 charts that are saved as html using this code sample:

library(networkD3)
library(magrittr)

Source <- c("A", "A", "A", "A", "B", "B", "C", "C", "D")
Target <- c("B", "C", "D", "J", "E", "F", "G", "H", "I")
NetworkData <- data.frame(Source, Target)

simpleNetwork(NetworkData) %>% saveNetwork(file = 'Net1.html')
CJ Yetman
  • 8,373
  • 2
  • 24
  • 56
  • Hi Dmitry - Welcome to stackoverflow. Please show what work you've done so far. Thanks! https://stackoverflow.com/help/how-to-ask – Erty Seidohl Apr 03 '18 at 22:47
  • Possible duplicate of [linking a node in networkD3 to a website using clickAction = NULL](https://stackoverflow.com/questions/36895960/linking-a-node-in-networkd3-to-a-website-using-clickaction-null) – CJ Yetman Apr 05 '18 at 09:51

1 Answers1

0

You will need to use the forceNetwork() function in order to get that capability, plus some extra work.

(example largely based on @timelyportfolio's code here: linking a node in networkD3 to a website using clickAction = NULL)

library(networkD3)
library(magrittr)

data(MisLinks)
data(MisNodes)

fn <- forceNetwork(
  Links = MisLinks, Nodes = MisNodes, Source = "source",
  Target = "target", Value = "value", NodeID = "name",
  Group = "group", opacity = 0.4, zoom = TRUE
)

fn$x$nodes$hyperlink <- paste0(
  'http://en.wikipedia.org/wiki/Special:Search?search=',
  MisNodes$name
)

fn$x$options$clickAction = 'window.open(d.hyperlink)'

fn %>% saveNetwork(file = 'Net1.html')
CJ Yetman
  • 8,373
  • 2
  • 24
  • 56