Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotly plots are not shown on Sphinx 4 #9563

Closed
astrojuanlu opened this issue Aug 19, 2021 · 7 comments
Closed

Plotly plots are not shown on Sphinx 4 #9563

astrojuanlu opened this issue Aug 19, 2021 · 7 comments
Labels

Comments

@astrojuanlu
Copy link
Contributor

Describe the bug

As demonstrated in https://sphinx-widgets-test.readthedocs.io/en/latest/Plotly%20plot.html, Plotly plots are not shown in Sphinx 4, and a bunch of JavaScript errors appear on the console:

js-errors

However, if I switch to Sphinx 3, as in https://sphinx-widgets-test.readthedocs.io/en/sphinx-3/Plotly%20plot.html, the plots are shown normally and no JS errors can be seen:

Screenshot 2021-08-19 at 11-46-49 Plotly plot — Sphinx Widgets Test 0 1 documentation

This is with Alabaster, but in poliastro/poliastro#1308 I was using sphinx_rtd_theme, with identical result.

I am not sure where the bug is, since there are several systems interacting here (sphinx, nbsphinx, plotly). But I hope it serves as a good starting point for debugging.

How to Reproduce

Bad:

$ git clone https://github.com/astrojuanlu/sphinx-widgets-test
$ cd sphinx-widgets-test
$ pip install -r requirements.txt
$ cd docs
$ make html
$ # open _build/html/index and see the error

Good:

$ cd sphinx-widgets-test
$ git switch sphinx-3
$ cd docs
$ rm -rf _build
$ make html
$ # open _build/html/index and see that the plot displays correctly

Expected behavior

The plots show normally.

Your project

https://github.com/astrojuanlu/sphinx-widgets-test

Screenshots

No response

OS

Linux Mint

Python version

3.9

Sphinx version

Sphinx 3.5.4 (good) and 4.1.2 (bad)

Sphinx extensions

nbsphinx

Extra tools

No response

Additional context

No response

@astrojuanlu
Copy link
Contributor Author

astrojuanlu commented Aug 19, 2021

cc @nicolaskruchten @mgeier

@nicolaskruchten
Copy link

That MIME-type error suggests that there is a misconfiguration in your HTTP server such that the Plotly.js file cannot be interpreted as Javascript, at first read.

@astrojuanlu
Copy link
Contributor Author

To clarify, this happens both locally with python -m http.server as well as online as served by Read the Docs.

@nicolaskruchten
Copy link

I see a different error here: https://sphinx-widgets-test.readthedocs.io/en/latest/Plotly%20plot.html ... do you have a Plotly-compatible version of MathJax installed? Plotly is compatible with MathJax 2.7.9 but not 3.x.

@astrojuanlu
Copy link
Contributor Author

Indeed, https://sphinx-widgets-test.readthedocs.io/en/latest/Plotly%20plot.html loads MathJax 3. I tested changing the Sphinx configuration to MathJax 2 in https://sphinx-widgets-test.readthedocs.io/en/mathjax-2-sphinx-4/Plotly%20plot.html and looks like now the plot loads. Thanks @nicolaskruchten, I guess there is nothing else to do here.

@mgeier
Copy link
Contributor

mgeier commented Aug 19, 2021

@astrojuanlu
Copy link
Contributor Author

That solution works, thanks to both. Closing!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants