我在使用rCharts的spiderweb图时遇到了一些问题。图表未按预期显示。有什么想法吗?
library(shiny)
library(rCharts)
runApp(
list(ui = fluidPage(
tags$head(tags$script(src = "https://code.highcharts.com/highcharts.js"),
tags$script(src = "https://code.highcharts.com/highcharts-more.js"),
tags$script(src = "https://code.highcharts.com/modules/exporting.js"),
tags$script(src = "https://code.highcharts.com/modules/heatmap.js")
),
titlePanel(""),
tabsetPanel(
tabPanel("Highcharts Spiderweb",
showOutput("Spiderweb","highcharts"))
)
),
# server side
server = function(input, output){
output$Spiderweb <- renderChart2({
plot <- Highcharts$new()
table = data.frame(id = c("a1","g3","k5","y9","z11"),
value = c(252,345,421,189,236))
plot$chart(polar = TRUE, type = "line")
plot$xAxis(categories=table$id, tickmarkPlacement= 'on', lineWidth= 0)
plot$yAxis(gridLineInterpolation= 'polygon', lineWidth= 0, min= 0)
plot$series(data = toJSONArray2(table[,c("id","value")], json = F, names = F),
name = "Series", pointPlacement="on")
plot
})
}
)
)
感谢您的帮助:)
答案 0 :(得分:4)
尝试删除标签$ head,showOutput
将加载它们,此时Highcharts库正在加载两次,并且引发了highcharts错误16。
此外,当您分配系列时,您不需要JSON数组,data=table[,"value"]
可以正常工作。
以下是修改后的代码:
library(shiny)
library(rCharts)
runApp(
list(ui = fluidPage(
titlePanel(""),
tabsetPanel(
tabPanel("Highcharts Spiderweb",
showOutput("Spiderweb","highcharts"))
)
),
# server side
server = function(input, output){
output$Spiderweb <- renderChart2({
plot <- Highcharts$new()
table = data.frame(id = c("a1","g3","k5","y9","z11"),
value = c(252,345,421,189,236))
plot$chart(polar = TRUE, type = "line")
plot$xAxis(categories=table$id, tickmarkPlacement= 'on', lineWidth= 0)
plot$yAxis(gridLineInterpolation= 'polygon', lineWidth= 0, min= 0)
plot$series(data = table[,"value"],
name = "Series", pointPlacement="on")
plot
})
}
)
)
给出这个: