Skip to content

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

Closed

Description

@michaelbabyn

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

Activity

  1. fwetdb commented on Jun 7, 2022

    @fwetdb

    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"}});}\

  2. nicolaskruchten commented on Jun 7, 2022

    @nicolaskruchten
    Contributor

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

  3. fwetdb commented on Jun 7, 2022

    @fwetdb

    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?

  4. nicolaskruchten commented on Jun 7, 2022

    @nicolaskruchten
    Contributor

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

  5. fwetdb commented on Jun 7, 2022

    @fwetdb

    Awesome, thank you for the fast reaction!

  6. fwetdb commented on Jun 7, 2022

    @fwetdb

    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

  7. added a commit that references this issue on Jun 8, 2022
    3f7c5bf
  8. added a commit that references this issue on Jun 8, 2022
    2990c62
  9. nicolaskruchten commented on Jun 8, 2022

    @nicolaskruchten
    Contributor

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

  10. nicolaskruchten commented on Jun 8, 2022

    @nicolaskruchten
    Contributor

    (actually I can comment, and I did)

  11. nicolaskruchten commented on Jun 8, 2022

    @nicolaskruchten
    Contributor
  12. fwetdb commented on Jun 9, 2022

    @fwetdb

    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 ?

  13. nicolaskruchten commented on Jun 10, 2022

    @nicolaskruchten
    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!

  14. nicolaskruchten commented on Jun 10, 2022

    @nicolaskruchten
    Contributor

    Another release, coming up!

  15. nicolaskruchten commented on Jun 10, 2022

    @nicolaskruchten
    Contributor

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

    Sorry and thanks for pointing this out :)

  16. fwetdb commented on Jun 10, 2022

    @fwetdb

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions