使用D3与闪亮 - 可折叠树?

时间:2017-06-20 19:51:27

标签: d3.js shiny

我对Shiny和R有一个公平的理解,但我刚刚开始使用Javascript并且从未编写过HTML或CSS编码。我想学习使用D3.js构建一个可折叠的树(像this之类的东西)是否有任何教程我可以参考开始将D3.js集成到Shiny中?

我遇到了CollapsibeTree package,但我想学习如何自己构建一个。任何帮助将非常感谢!

1 个答案:

答案 0 :(得分:0)

这是使用diamonds数据集的小地图示例。您可以在此处找到更多示例https://github.com/AdeelK93/collapsibleTree

library(shiny)
#install.packages("collapsibleTree")
library(collapsibleTree)

data(diamonds,package = "ggplot2")
subdiamonds <- diamonds[1:300,]

ui <- fluidPage(
  mainPanel(
    collapsibleTreeOutput("tree")
  )
)

server <- function(input, output, session) {

  output$tree <- renderCollapsibleTree({
    collapsibleTree(
      subdiamonds,
      hierarchy = c("cut", "color","price"),
      width = 800
    )
  })

}

shinyApp(ui = ui, server = server)

enter image description here