R collapsibleTree:在工具提示中动态添加图像

Bun*_*nny 4 html javascript r

这是一个很好的显示层次结构的包。

根据collapsibleTree 包提供的文档

在下面的代码中,他在工具提示中使用了图像。

org$tooltip <- paste0(
org$Employee,
"<br>Title:",
org$Title,
"<br><img src='https://source.unsplash.com/collection/385548/150x100'>"
)

collapsibleTreeNetwork(
org,
attribute = "Title",
fill = "Color",
nodeSize = "leafCount",
tooltipHtml = "tooltip"
)
Run Code Online (Sandbox Code Playgroud)

这里每个气泡都显示一个图像。

在我的表格中,我有一列每个员工的图像。 在此输入图像描述

现在,例如 A Employee --> 应该显示图像 A。同样,它应该向所有员工展示。

是否可以。

任何建议将不胜感激。

谢谢莫汉五世

luk*_*keA 6

这里每个气泡都显示一个图像。[...] 我们可以向他们尊敬的员工泡泡动态展示这些图像吗?

根据包作者在 GitHub 上的示例,以下是每个节点具有不同图片的示例:

library(collapsibleTree)
org <- data.frame(
  Manager = c(
    NA, "Ana", "Ana", "Bill", "Bill", "Bill", "Claudette", "Claudette", "Danny",
    "Fred", "Fred", "Grace", "Larry", "Larry", "Nicholas", "Nicholas"
  ),
  Employee = c(
    "Ana", "Bill", "Larry", "Claudette", "Danny", "Erika", "Fred", "Grace",
    "Henri", "Ida", "Joaquin", "Kate", "Mindy", "Nicholas", "Odette", "Peter"
  ),
  Title = c(
    "President", "VP Operations", "VP Finance", "Director", "Director", "Scientist",
    "Manager", "Manager", "Jr Scientist", "Operator", "Operator", "Associate",
    "Analyst", "Director", "Accountant", "Accountant"
  )
)

# Add in colors and sizes
org$Color <- org$Title
levels(org$Color) <- colorspace::rainbow_hcl(11)

org$tooltip <- sprintf("
  %s<br>Title: %s<br><img src='%s'>", 
  org$Employee, 
  org$Title, 
  paste0("https://github.com/twitter/twemoji/blob/gh-pages/72x72/1f19", c(1, 1:9, letters[1:6]), ".png?raw=true")
)

collapsibleTreeNetwork(
  org,
  attribute = "Title",
  fill = "Color",
  nodeSize = "leafCount",
  tooltipHtml = "tooltip"
)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述