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

graphs from plotly >= 5.8 don't render in databricks #3756

Closed
michaelbabyn opened this issue Jun 2, 2022 · 14 comments
Closed

graphs from plotly >= 5.8 don't render in databricks #3756

michaelbabyn opened this issue Jun 2, 2022 · 14 comments

Comments

@michaelbabyn
Copy link
Contributor

displaying a python figure in an iframe within databricks works with plotly==5.7 but when I attempt to do it using 5.8 it fails with Uncaught SyntaxError: Unexpected token '&&':

Screenshot from 2022-06-02 10-56-02

@fwetdb
Copy link

fwetdb commented Jun 7, 2022

How to fix:

  1. by plotly: publish a new plotly version on Pypi that fixes this error
  2. by users:
    Until the fix is released by plotly on pypi, users can self-fix via adding the following code to their python scripts or notebooks:
import plotly.io._html as piohtml
piohtml._mathjax_config = """<script type="text/javascript">if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: "STIX-Web"}});}</script>"""

Background:
This error affects Databricks notebooks with plotly==5.8.0 (and potentially other environments that use a Plotly HTML renderer)
I stumbled across this as part of my work for Databricks.

The root cause of the error is in https://github.com/plotly/plotly.py/blob/HEAD/packages/python/plotly/plotly/io/_html.py#L23

There is a duplicate, consequent &&

The line should say:
if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: "STIX-Web"}});}\

@nicolaskruchten
Copy link
Contributor

Thanks @fwetdb! I'm embarrassed that that got through code review 🙈

@fwetdb
Copy link

fwetdb commented Jun 7, 2022

You're welcome! I am glad that I could help! Without plotly being so widely used and open-source at the same time, this fix (including the investigation) would have been neither needed nor possible.

What are your thoughts on the timeline when the fix can be released, @nicolaskruchten ?
Should I open a PR or will you do it internally?

@nicolaskruchten
Copy link
Contributor

No need for a PR, I can do it. I will try to do a point release tonight or tomorrow morning.

@fwetdb
Copy link

fwetdb commented Jun 7, 2022

Awesome, thank you for the fast reaction!

@fwetdb
Copy link

fwetdb commented Jun 7, 2022

There is a stackoverflow question that relates to this. I wanted to comment but I do not have enough reputation for that. Also, I was not able to answer.

Can someone refer them to this issue?
https://stackoverflow.com/questions/72466969/plotly-uncaught-syntaxerror-unexpected-token

nicolaskruchten added a commit that referenced this issue Jun 8, 2022
@nicolaskruchten
Copy link
Contributor

@fwetdb I can't reply to a closed question either, sorry

@nicolaskruchten
Copy link
Contributor

(actually I can comment, and I did)

@nicolaskruchten
Copy link
Contributor

@fwetdb
Copy link

fwetdb commented Jun 9, 2022

I tried to verify the bug fix but it seems to me like the release does not contain the new code?

Here is what I executed both in a cell both in Databricks and in a binder notebook e.g. the one at bamboolib.com/demo

!pip install plotly==5.8.1

import plotly
plotly.__version__ # 5.8.1

import plotly.io._html as piohtml
display(piohtml._mathjax_config)  # still contains the duplicate &&

import plotly.express as px
df = px.data.medals_long()

fig = px.bar(df, x="medal", y="count", color="nation")
fig

This still shows the error (because the mathjax config is still the old one).

What do you think @nicolaskruchten ?

@nicolaskruchten
Copy link
Contributor

Huh, that's very strange. I'll admit I didn't do this check myself, I merged the PR and ran the build process so something must be wrong with the build process :(

I'll dig into it and do another release. Sorry!

@nicolaskruchten
Copy link
Contributor

Another release, coming up!

@nicolaskruchten
Copy link
Contributor

OK here we go: https://github.com/plotly/plotly.py/releases/tag/v5.8.2

Sorry and thanks for pointing this out :)

@fwetdb
Copy link

fwetdb commented Jun 10, 2022

Great, thank you and I validated that 5.8.2 works as expected.
Again, awesome response time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants