Strange symbol “” appearing from rChart sankey

2019-05-18 21:02发布

问题:

Here's a screenshot of the output:

The problem seems to be with the $setLib() function. As depending on the directory given, it gives a corresponding string output. Providing the correct directory produces the symbol .

For example providing a URL produces this output without the chart:
Code -sankeyPlot$setLib("https://github.com/timelyportfolio/rCharts_d3_sankey")
Output - https://github.com/timelyportfolio/rCharts_d3_sankey/layouts/chart.html


Here's a sample code to replicate the error:

require(rCharts)
require(rjson)
require(shiny)

links <- matrix(unlist(
  rjson::fromJSON(
    file = "http://bost.ocks.org/mike/sankey/energy.json"
  )$links
),ncol = 3, byrow = TRUE)
nodes <- unlist(
  rjson::fromJSON(
    file = "http://bost.ocks.org/mike/sankey/energy.json"
  )$nodes
)
#convert to data.frame so souce and target can be character and value numeric
links <- data.frame(links)
colnames(links) <- c("source", "target", "value")
links$source <- sapply(links$source, FUN = function(x) {return(as.character(nodes[x+1]))}) #x+1 since js starts at 0
links$target <- sapply(links$target, FUN = function(x) {return(nodes[x+1])}) #x+1 since js starts at 0


server <- function(input, output) {
  output$sankey <-  renderChart2({

    sankeyPlot <- rCharts$new()
    sankeyPlot$setLib("./d3_sankey")

    sankeyPlot$set(
      data = links,

      nodeWidth = 15,
      nodePadding = 15,
      layout = 30

    )
    return(sankeyPlot)
  })
}

ui <- fluidPage(
  showOutput('sankey', 'd3_sankey')
)

shinyApp(ui = ui, server = server)