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 interactive plots not showing in Jupyter book #2096

Closed
rohanjha123 opened this issue Jan 7, 2024 · 4 comments
Closed

Plotly interactive plots not showing in Jupyter book #2096

rohanjha123 opened this issue Jan 7, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@rohanjha123
Copy link

rohanjha123 commented Jan 7, 2024

Describe the bug

Hi, I'm running into the same issue as #93 but unfortunately their fix didn't quite work for me. This is what my Plotly plot looks like in my local jupyter lab instance:
Screen Shot 2024-01-07 at 2 43 21 PM
As the plot renders fine locally, I would expect it to also render in the book. However, I'm afraid that plot simply doesn't appear in the locally rendered jupyter book:
Screen Shot 2024-01-07 at 2 44 37 PM.
This is a problem for me as I'm attempting to make a book that would involve teaching visualizations in Python, and interactive plots made with Plotly are essential for teaching that.

Reproduce the bug

Here is a link to the notebook which is causing these issues. Try cloning my repo and rendering it locally.

Note: I've tried everything in this thread, and my config.yaml includes the following lines:

sphinx:
  config:
    html_js_files:
    - https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js

List your environment

(sklearn-env) rohanjha@Rohans-Air textbook % jupyter-book --version
Jupyter Book      : 0.15.1
External ToC      : 0.3.1
MyST-Parser       : 0.18.1
MyST-NB           : 0.17.2
Sphinx Book Theme : 1.0.1
Jupyter-Cache     : 0.6.1
NbClient          : 0.5.13

plotly version 5.9.0
Python 3.11.1
rendered locally with jupyter lab 3.6.3, on Chrome 120.0 (using arm64 architecture) on a MacOS

@agoose77
Copy link
Collaborator

Thanks for the report! Did you delete the book from your repo? I can no longer see it.

@rohanjha123
Copy link
Author

Oops, I instead moved my repo here. Here is the new link to the notebook, and here is the rendered page where the plot doesn't work. Sorry for not updating this post sooner!

@agoose77
Copy link
Collaborator

agoose77 commented Jan 11, 2024

I was able to reproduce the issue. Here's what fixed it for me:

  1. Use the default display mechanism, by changing the last lines of your plotly cell in content/04-visualizations/types to
    # Set title/axis labels
    fig.update_layout(
        title='Proportion enrolled in Primary School, using data from 1970 to 2014',
        xaxis=dict(title='Percent of Males'),
        yaxis=dict(title='Percent of Females'),
        legend=dict(x=0.05, y=0.9)
    )
    fig
  2. Update your Sphinx config, rather than replacing
    sphinx:
      recursive_update: true
      config:
        html_js_files:
          - "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"

@rohanjha123
Copy link
Author

That fixed it for me! Thank you so so much!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants