You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know how this is supposed to work.
Your example has two output cells. The first one has two alternative contents of the type text/vnd.plotly.v1+html and text/html, respectively. The second output cell also has two alternative contents with the same two types. nbsphinx includes the text/html part in both cases, because it doesn't know the other type.
When loading the Sphinx-generated HTML page, I get those errors in the JS Console:
ReferenceError: define is not defined
ReferenceError: require is not defined
Thanks for checking it out with nbconvert.
Since it is working there, I only had to check what they are doing and I found the problem: require.js is not available!
Since nobody has missed it before, I don't think it's worth including it by default in nbsphinx.
@mgeier I would opt for adding require.js to nbsphinx by default.
I have been tackling this issue (which now seems obvious) for some time, mostly because there are a lot of things involved and you don't know where is the problem - jupyter, plotly, sphinx, nbsphinx, rtd, or your code :)
We had this issue for both sphinx_rtd_theme and furo theme. Because how Plotly and Sphinx themes using require.js, the default generated HTML output does not work within Sphinx context. You get various loading errors with require.js or other files.
Here is our solution:
Make sure your JavaScript loads at <head> in your theme. If it loads at the end of the <body> no workaround is going t work.
Server require.js locally from Sphinx _static folder
Configure require by using custom.js
Example conf.py:
html_js_files= [
"require.min.js", # Add to your _static"custom.js",
]
Activity
mgeier commentedon Oct 7, 2017
bluprince13 commentedon Oct 15, 2017
https://gist.github.com/bluprince13/1a53aabe99b5a4a1ec2007a90889115b
The plots don't render on Github either.
mgeier commentedon Oct 17, 2017
OK, thanks for the example.
Just for the record, it seems to work on nbviewer: http://nbviewer.jupyter.org/gist/bluprince13/1a53aabe99b5a4a1ec2007a90889115b
Does it work with
nbconvert?I don't know how this is supposed to work.
Your example has two output cells. The first one has two alternative contents of the type
text/vnd.plotly.v1+htmlandtext/html, respectively. The second output cell also has two alternative contents with the same two types.nbsphinxincludes thetext/htmlpart in both cases, because it doesn't know the other type.When loading the Sphinx-generated HTML page, I get those errors in the JS Console:
bluprince13 commentedon Oct 18, 2017
I asked a question on stackoverflow on this as well. No responses yet.
bluprince13 commentedon Oct 18, 2017
I can confirm that this does work with nbconvert 5.3.1. So, why is the Sphinx generated documentation not showing it ...
mgeier commentedon Oct 19, 2017
Thanks for checking it out with
nbconvert.Since it is working there, I only had to check what they are doing and I found the problem: require.js is not available!
Since nobody has missed it before, I don't think it's worth including it by default in
nbsphinx.For now, you can use this in your
conf.py:... but probably there is a better solution?
Any ideas?
bluprince13 commentedon Oct 20, 2017
Hmmm...did you check if it solves the problem? It didn't work for me, but I am not sure if there was some other factor at play.
In terms of a solution, is it feasible to get nbsphinx to generate a meaningful warning if there are missing scripts?
mgeier commentedon Oct 21, 2017
Yes, I checked.
No, I don't think that's possible.
astrojuanlu commentedon Nov 15, 2017
I have tried this workaround, but still I get the
ReferenceError: requirejs is not defined.Code: poliastro/poliastro@master...Juanlu001:master
Build: https://readthedocs.org/projects/juanlu-poliastro/builds/6272017/
Result: http://juanlu-poliastro.readthedocs.io/en/latest/examples/Plotting%20in%203D.html (edit: this might be unavailable for future readers)
I suspect this is because the scripts are loaded at the bottom of the page, after
require.jsis requested by the plotly graphs.astrojuanlu commentedon Nov 16, 2017
I see you're tracking this here readthedocs/sphinx_rtd_theme#328
mgeier commentedon Nov 17, 2017
Did you try it with a different HTML theme?
astrojuanlu commentedon Nov 17, 2017
I can confirm locally that using a different theme fixes the problem, so this is not a nbsphinx issue.
mgeier commentedon Nov 18, 2017
@Juanlu001 OK, thanks! Did you try if readthedocs/sphinx_rtd_theme#467 fixes the problem?
astrojuanlu commentedon Nov 18, 2017
Yes it does! 😁 see readthedocs/sphinx_rtd_theme#467 (comment)
astrojuanlu commentedon Jun 28, 2018
readthedocs/sphinx_rtd_theme#467 was closed because it was too complex, but now the issue is being tackled at readthedocs/sphinx_rtd_theme#545.
astrojuanlu commentedon Sep 23, 2018
Some more info in readthedocs/readthedocs.org#4367 (comment)
mgeier commentedon Dec 11, 2018
readthedocs/sphinx_rtd_theme#545 has finally been merged into the
masterbranch, now we only have to wait for a new release ...manycoding commentedon May 2, 2019
@mgeier I would opt for adding
require.jstonbsphinxby default.I have been tackling this issue (which now seems obvious) for some time, mostly because there are a lot of things involved and you don't know where is the problem - jupyter, plotly, sphinx, nbsphinx, rtd, or your code :)
mgeier commentedon May 3, 2019
@manycoding I guess if
nbconvertandnbviewerincluderequire.js, it makes sense to have it innbsphinx, too.Would you like to make a PR?
miohtama commentedon Jun 17, 2022
We had this issue for both
sphinx_rtd_themeandfurotheme. Because how Plotly and Sphinx themes usingrequire.js, the default generated HTML output does not work within Sphinx context. You get various loading errors with require.js or other files.Here is our solution:
<head>in your theme. If it loads at the end of the<body>no workaround is going t work.require.jslocally from Sphinx_staticfolderrequireby using custom.jsExample
conf.py:Example custom.js:
This way
See the example open-source documentation here and the example notebook.