R中Highcharts的蜘蛛网图问题

Problems with spiderweb graph from Highcharts in R

我在使用 rCharts 的蜘蛛网图时遇到了一些问题。图形未按应有的方式显示。有什么想法吗?

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
        })
      }
      )
    )

感谢您的帮助:)

尝试删除标签$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
                })
        }
        )
)

给出这个: