10

Background: I am new to the Python world and am using Plotly for creating basic graphs in Python. I am using AWS Sagemaker's JupyterLab for creating the python scripts.

Issue: I have been trying to run the basic codes mentioned on Plotly's website however even those are returning blank graphs.

Issue Resolution Tried by myself:

  1. pip installed plotly version 4.6.0

  2. Steps mentioned on https://plotly.com/python/getting-started/ for JupyterLab support have already been executed

Code Example:

import plotly.graph_objects as go
fig = go.Figure(data=go.Bar(y=[2, 3, 1]))
fig.show()
Sid
  • 101
  • 1
  • 3

3 Answers3

2

I recently had the same issue. Simple change suggested here helped me. I know this is a temporary workaround until a proper fix is found.

// fig = go.Figure()
fig = go.FigureWidget()    // replace with this
// fig.show()
fig                        // remove .show()
PraAnj
  • 899
  • 1
  • 10
  • 27
2

Sagemaker notebook instances are using (As of Jan 2022), for some reason, jupyterlab==1.2.21. You can verify that by running pip freeze | grep lab from the terminal or !pip freeze | grep lab from a notebook.

According to the documentation, you'll need to install the following jupyterlab extensions (which are not needed if sagemaker was running jupyterlab 3):

  • jupyterlab-plotly
  • jupyter-widgets/jupyterlab-manager

You can install those on a up-and-running instance by running jupyter labextension install jupyterlab-plotly@5.5.0 @jupyter-widgets/jupyterlab-manager in the terminal or notebook (using ! if you are running on the notebook ofcourse). Notice that the jupyterlab-plotly extension version (here 5.5.0) should match the plotly version you are installing. Mismatches my cause issues. In this case by plotly version is 5.5.0 and thus that's also the jupyterlab-plotly version I've installed.

If you need, like I did, to have it ready upon spinning up a notebook instance, you'll need to:

  • Create a lifecycle script
  • To it, add:
    • PATH=$PATH:/home/ec2-user/anaconda3/envs/JupyterSystemEnv/bin - To ensure nodejs path which is needed for the extension installation
    • pip install plotly==5.5.0 - To ensure a specific version
    • jupyter labextension install jupyterlab-plotly@5.5.0 @jupyter-widgets/jupyterlab-manager - To ensure same version

of coures, you can change the version according to the most up to date.

idoda
  • 6,248
  • 10
  • 39
  • 52
1

I think that documentation is not on par. You now need to install jupyterlab-plotly extension.

jupyter labextension install jupyterlab-plotly

UPDATE I followed a mix of instructions here and here.

First Enable Extention manager from jupyter-lab then from terminal

conda  install -c conda-forge "nbformat" "ipywidgets>=7.5" -y

jupyter labextension install jupyterlab-plotly
jupyter labextension install @jupyter-widgets/jupyterlab-manager plotlywidget

And within your environment

conda install nbformat
rpanai
  • 12,515
  • 2
  • 42
  • 64
  • Hi @rpanai, tried your code. It went in a loop stating "jupyterlab-plotly@file:../extensions/jupyterlab-plotly-4.6.0.tgz" This went on coming for about 13 minutes and then the program exited. Have tried this multiple times but haven't been of help. – Sid Apr 15 '20 at 05:19