将 networkd3 节点点击重定向到基于值的动态 url

Redirecting networkd3 node click to a dynamic url based on a value

我正在尝试构建链接对象的交互式网络可视化。 我已经在以下位置查看了代码: https://christophergandrud.github.io/networkD3/

但无法找到可帮助我将节点转换为可重定向用户或启动新浏览器的可点击 URL 的代码示例 window。 这可能吗? 我的问题与使用此代码示例保存为 html 的 networkD3 图表有关:

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')

您需要使用 forceNetwork() 函数才能获得该功能,此外还需要做一些额外的工作。

(示例主要基于此处@timelyportfolio 的代码:

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')