问题似乎与$setLib()
功能有关。根据给定的目录,它给出了相应的字符串输出。提供正确的目录会生成符号
。
例如,提供URL会生成此输出而不显示图表:
代码 - sankeyPlot$setLib("https://github.com/timelyportfolio/rCharts_d3_sankey")
输出 - https://github.com/timelyportfolio/rCharts_d3_sankey/layouts/chart.html
以下是复制错误的示例代码:
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)