Sankey粒子可视化

时间:2017-09-07 10:37:35

标签: r d3.js rcharts sankey-diagram htmlwidgets

我非常喜欢Sankey图的粒子可视化  https://bl.ocks.org/micahstubbs/6a366e759f029599678e293521d7e26c

然而,我不能在R闪亮中复制相同内容,因为我对嵌入脚本没有任何了解。下面是创建一个sankey闪亮应用程序的代码 关于如何实现它的任何帮助/指示都会有所帮助。

#ui
library(shiny)
library(rCharts)

shinyUI(bootstrapPage(
  div(
    class="container-fluid",
    div(class="row-fluid",
        headerPanel("Path Explorer") 
    ),
    div(class="row-fluid",
        sidebarPanel(
          h4("Sankey Visualisation")
        ),
        mainPanel(
          tableOutput("table"),
          showOutput('sankey' ,'C:/Users/neha.sharma/Desktop/rCharts_d3_sankey-gh-pages/libraries/widgets/d3_sankey') # I refer to this directory later on in this message
        )
    )
  )
))


#server

library(shiny)
library(rCharts)

shinyServer(function(input, output){
  data <- reactive({
    data <- data.frame(
      source = c("peugot","Tagesschau.de","BMW.DE","DirectExit","Amazon.de","Google.com","BMW.DE","BMWgroup.com","facebook","directaccess","BMW.DE","Peugot","bing1","bing","BMW.DE","Mobile.DE"),
      target = c("Tagesschau.de", "BMW.DE","DirectExit","DirectExit2","Google.com","BMW.DE","BMWgroup.com","BMWAuto","directaccess", "BMW.DE" ,"Peugot", "Peugot(2)","bing","BMW.DE","Mobile.DE","Mobile_Last"),
      value=c("8","6.3","5.5","5.4","5.4","23.5","11","5.4","3","5","4.5","8","6.3","5.5","5.4","5.4"))
    #return(data)
  })



  #output$table <- renderTable({
   # return(data())
  #})


  output$sankey <-  renderChart2({  
    sankeyPlot <- rCharts$new()
    sankeyPlot$setLib("C:/Users/neha.sharma/Desktop/rCharts_d3_sankey-gh-pages/libraries/widgets/d3_sankey")
    #C:/Users/neha.sharma/Desktop/rCharts_d3_sankey-gh-pages/libraries/widgets/d3_sankey
    sankeyPlot$set(
      data = data(),

      nodeWidth = 15,
      nodePadding = 10,
      layout = 40,#32
      labelFormat = ".1%",
      width = 800,
      height = 600
    )

   return(sankeyPlot)
  })
})

0 个答案:

没有答案