Problems with spiderweb graph from Highcharts in R

冷暖自知 提交于 2019-12-12 01:47:19

问题


I've got some problems using spiderweb graphs from rCharts. Graph is not displaying as it should be. Any ideas ?

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

Thanks for helping :)


回答1:


Try removing the tags$head, showOutput will load them, right now the Highcharts libs are being loaded twice, and highcharts error 16 is raised.

Also, when you assign the series, you don't need the JSON array, data=table[,"value"] works fine.

Here is the modified code:

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

Gives this:



来源:https://stackoverflow.com/questions/28282646/problems-with-spiderweb-graph-from-highcharts-in-r

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