Search code examples
rplothighchartsshinyrcharts

rCharts and highcharts with shiny plot does not update correctly


I've created a custom plotting function for a scatterplot with error bars on multiple series using rCharts. I successfully embedded said plot in a shiny application. The first time it shows everything works fine:

enter image description here

However, if I try to update the plot (e.g. by changing some input) the plot does not change and I get the following JS error message on the browser's console:

TypeError: 'undefined' is not a function (evaluating 'this[b].destroy()')

The strange thing is that if I check the plot object (p) it seems fine, e.g. I can plot it in Rstudio and also get a viable html page from it. I guess the problem is somehow that the old plot cannot be removed properly.

I use rCharts v. 0.4.5 and shiny 0.10.2.1 and I have uploaded an example shiny app to github:

https://github.com/mlist/highcharts_scatterplot_example

As extra dependency you will need to install the packages rjson and foreach. You can then run the app with

runGitHub(repo="mlist/highcharts_scatterplot_example")

```


Solution

  • Use renderChart2 rather then renderChart. Replace output$testPlot with :

      output$testPlot <- renderChart2({
        p <- highcharts.scatterplot.plate(data.frame(seq(1:nrow(iris)),iris[,2], input$error, iris[,5]))
        return(p)
      })
    

    You can try the change at:

    shiny::runGitHub(repo="johndharrison/highcharts_scatterplot_example")