Search code examples
pythonhighcharts

Highcharts for Python doesn't render in Jupyter


I am trying out highcharts-core for Python to display js based charts. github.com/highcharts-for-python/highcharts-core

Using the sample code from the docs:

from highcharts_core.chart import Chart
from highcharts_core.options.series.area import LineSeries
from highcharts_core.global_options.shared_options import SharedOptions

my_chart = Chart(container = 'target_div',
                 options = {
                     'series': [
                         LineSeries(data = [0, 5, 3, 5])
                     ]
                 },
                 variable_name = 'myChart')

# Now this will render the contents of "my_chart" in your Jupyter Notebook
my_chart.display()

I get the following "error" once the cell finishing running after about 3 seconds:

Something went wrong with the Highcharts.js script. It should have been automatically loaded, but it did not load for over 3 seconds. Check your internet connection, and then if the problem persists please reach out for support.

what might be going on here?


Solution

  • Chiming in as the author of the Highcharts for Python toolkit. I'm having some difficulty reproducing the issue you're seeing.

    What version of Highcharts Core for Python are you using, and what version of Jupyter Notebook (or Jupyter Labs)?

    Generally, that error message appears if the chart does not render in about 3 seconds. The most common reason for this is temporary network issues which delay the loading of the JavaScript modules that are needed for the chart to render. Those JavaScript modules get loaded asynchronously the first time you try to display a Highcharts visualization in your notebook. If that is - indeed - the cause, if you clear the output of that cell and re-run the cell it may render correctly for you (because by that point the scripts will have asynchronously been loaded successfully).

    Hope this helps, and feel free to provide some more background if you're continuing to run into this issue - with more details like the versions of Jupyter you're using and the version of the Highcharts Core for Python library you're using, that can help diagnose the issue if it isn't just momentarily network latency.

    ETA: Turns out the problem was resolved after upgrading to v.1.1.1 of the Highcharts for Python library, and also disabling and re-enabling some of the Jupyter Notebook-related VSCode extensions. It's unclear whether the sequence of disabling/re-enabling the VSCode extensions mattered for the resolution, or whether it was one specific extension causing a conflict, or whether it was a combination of the extensions. The extensions indicated for further research are: Jupyter, Jupyter Cell Tags, Jupyter Notebook Renderers, Jupyter Slide Show, Jupyter Keymap.