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

How to save collapsible treegram generated by collapsibleTree to html file in R

collapsibleTree 是一个在 R 中生成可折叠树图的 auesome 包。有谁知道我们如何将生成的树图保存为 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)

您可以使用 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")

注意后面一个会抱怨没有标题