如何将由collapsibleTree生成的可折叠树图保存到R中的html文件中

时间:2019-12-10 16:32:12

标签: r htmlwidgets

collapsibleTree是在R中生成可折叠树图的绝妙包。有人知道我们如何将生成的树图保存为html文件吗?

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"
    )
)
library(collapsibleTree)
collapsibleTree(org, c("Manager", "Employee"), collapsed = FALSE)

1 个答案:

答案 0 :(得分:1)

您可以使用htmltools::save_htmlhtmlwidgets::saveWidget

c = collapsibleTree(org, c("Manager", "Employee"), collapsed = FALSE)
htmltools::save_html(c, file='file.html')
htmlwidgets::saveWidget(c, file="file2.html")

请注意,后者会抱怨没有标题。