-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 show locally but not on RTD #4367
Comments
I do see the plots in Firefox 61.0.1 (64-bits) on Linux Arch even with the errors that are shown in the Firefox console. On the other hand in Chrome it works, does not work, crashes my Chrome and behaves in a crazy way 😁 We will need to research more about this, but I can tell that after refreshing a couple of times the page from Chrome Versión 61.0.3163.79 (Build oficial) (64 bits) (with and without cache) I was able to see the graph: I'd say that there is something that depends on the order of loading those js libraries... I'm not sure how to continue debugging this, though. |
Thanks for your prompt response @humitos! If there's anything I can do to help from my side, please let me know. |
I created a repo with a much simpler test case to display the buggy behavior: https://github.com/Juanlu001/rtd-js-test Result: https://rtd-js-test.readthedocs.io/ There are two branches (one with the RTD theme and one with Alabaster) and five notebooks that display four different combinations + an interactive widget.
I still did not have time to test what @Blendify started in readthedocs/sphinx_rtd_theme#545, but the fact that Alabaster does not show display this behavior would indicate that there it's a RTD + RTD theme specific behavior. @jonmmease suggested in plotly/plotly.py#1033 that the problem might be require.js rather than jQuery. Also, although this was first reported in spatialaudio/nbsphinx#128, I doubt that this can be fixed on the nbsphinx side (cc @mgeier, @bluprince13). My current workarounds are:
I acknowledge that we have to conceal expectations and settle on who should handle this, so can we try to reach an agreement? |
By the way, one of the JS errors I'm getting contains the string |
Can you tell me where you see this error? I don't see it on |
As to fixing the underlying issue, that will be done here: Until then, try the workaround documented here: In general, you get better performance by loading JS at the end of the page rather than in the head as loading JS blocks rendering until it is fetched. However, no other Sphinx theme seems to care about that performance so I guess the RTD theme won't either. |
I see that error here: https://rtd-js-test.readthedocs.io/en/latest/Connected%20-%20require.js%20Hack.html Glad to know readthedocs/sphinx_rtd_theme#545 is still under consideration, I was worried because the branch is lagging a bit behind :) The problem with the workaround is that it's not that easy to modify the output of nbsphinx, as it's not a |
Thanks. I see that in the error and that's very weird. However, I don't think that's the cause of the error. |
In #4787 (comment) I encountered the same problem. I fixed it by (copy from that issue): def remove_jquery_and_underscore(app):
# We need to remove the jquery and underscore file that are
# added by default because we already add it in the <head> tag.
remove = lambda x: not any(js in x for js in ['jquery', 'underscore'])
if hasattr(app.builder, 'script_files'):
app.builder.script_files = [x for x in app.builder.script_files
if remove(x)]
def setup(app):
app.connect('builder-inited', remove_jquery_and_underscore) Using my setup I am able to correctly show plotly plots, for example https://adaptive.readthedocs.io/en/latest/docs.html#adaptive-learnernd. |
I used @Blendify branch at readthedocs/sphinx_rtd_theme#545 and it worked: https://rtd-js-test.readthedocs.io/en/fork-theme/ No JS errors whatsoever, all the plots work. It would be great to have this in |
I tried rebasing PR readthedocs/sphinx_rtd_theme#545, but this is indeed quite hard. But the end result should really be just moving a few lines around, so I made a new PR doing just that: readthedocs/sphinx_rtd_theme#696. Can you please check out if that works for you? |
readthedocs/sphinx_rtd_theme#545 was merged, should we wait for a new release of the theme or close this now? |
We can close. |
Rebuilding @Juanlu001's repo locally with |
@dgasmith, we had the same problems in Adaptive. I am not a javascript expert but we solved it in Adaptive, basically by copying I am not sure whether the presence of that line (loading jQuery with require.js when it's already loaded) is a bug or not. Maybe @stsewd or @Blendify would know? |
Before deeming this a problem with sphinx_rtd_theme, let me repeat the tests. The ipywidgets ecosystem is evolving very fast, sometimes in a not so organic way, and perhaps there's something that broke on the other side. |
@Juanlu001, in Adaptive we use Again, I don't know whether this is the best solution. |
Glad to know it's working for you @basnijholt. For me, however, things look a bit more complicated because I tested several combinations of plotly and sphinx-rtd-theme with the latest versions of all the packages, including ipywidgets, and... Now nothing seems to work. @jonmmease is reworking Plotly rendering in plotly/plotly.py#1474, so perhaps that has the potential of fixing these issues (once and for all?) In the meanwhile, I will try to go back to some known configuration that worked and identify where the problem is, although it will take me some time. Amend: In alabaster everything seems to work, but now I can't find any version of plotly + sphinx-rtd-theme that does, not even the fork I used to use. |
(Clarified previous comment with respect to alabaster) |
@basnijholt Your solve work great! One small addendum, we need to to add |
Plotly merged a significant refactor of their render machinery, so it would be nice to repeat the tests with the master version (or wait for the next release if you're patient enough): |
I am using alabaster, and graphs are not shown. I am not sure if it's a rtd or nbsphinx issue. |
@manycoding I see a |
@Juanlu001 Yeah, that's probably |
An update after #4367 (comment): I didn't rebuild |
My issue is being fixed in spatialaudio/nbsphinx#302 |
Details
Expected Result
I expected the Plotly plots to show in RTD the same way as locally.
Actual Result
Because of readthedocs/sphinx_rtd_theme#328, I am using a hack, which is adding
require.js
at the top of the page from a notebook cell:https://juanlu-poliastro.readthedocs.io/en/latest/examples/Visualizing%20the%20SpaceX%20Tesla%20Roadster%20trip%20to%20Mars.html
I tried to build locally and the result is correctly seen in Firefox and Chrome.
When deploying to RTD, on Firefox this gives several JavaScript
ReferenceError
s but the plot loads. These errors come from RTD scripts:In Chrome, on the other hand, I get similar errors but the plot never loads.
When I try to add jQuery as suggested in plotly/plotly.py#1033 (comment):
https://juanlu-poliastro.readthedocs.io/en/latest/examples/Plotting%20in%203D.html
Then I get errors coming from
require.js
and the plot doesn't load in Firefox nor Chrome.The text was updated successfully, but these errors were encountered: