Strange symbol “” appearing from rChart sankey output in Shiny

倾然丶 夕夏残阳落幕 提交于 2019-12-07 19:32:34

问题


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)

来源:https://stackoverflow.com/questions/37264754/strange-symbol-%c3%af-appearing-from-rchart-sankey-output-in-shiny

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!