Reputation: 667
The following code does not render in Jupyter lab:
%matplotlib widget
import plotly.express as px
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randint(0,100,size=(5, 4)), columns=list('ABCD'))
px.bar(df, x='A', y='B')
I have tried to install all the dependencies and extensions mentioned in here https://plot.ly/python/getting-started/#jupyterlab-support-python-35
but also the steps in here https://github.com/matplotlib/jupyter-matplotlib
Nothing worked
Here is my set up:
jupyter lab --version
1.0.2
python --version
Python 3.6.1 :: Continuum Analytics, Inc.
conda list jupyterlab
# packages in environment at C:\Users\***\Anaconda3:
#
# Name Version Build Channel
jupyterlab 1.0.2 py36hf63ae98_0
jupyterlab_launcher 0.13.1 py36_0
jupyterlab_server 1.0.0 py_0
conda list nodejs
# packages in environment at C:\Users\***\Anaconda3:
#
# Name Version Build Channel
nodejs 0.1.1 pypi_0 pypi
conda list plotly
# packages in environment at C:\Users\***\Anaconda3:
#
# Name Version Build Channel
plotly 4.1.0 pypi_0 pypi
plotly-express 0.4.1 pypi_0 pypi
EDIT:
jupyter-labextension list
JupyterLab v1.0.2
Known labextensions:
app dir: C:\Users\***\Anaconda3\share\jupyter\lab
@jupyter-widgets/jupyterlab-manager v1.0.2 enabled ok
@jupyterlab/git v0.8.0 enabled ok
@jupyterlab/plotly-extension v1.0.0 enabled ok
jupyter-matplotlib v0.4.2 enabled ok
jupyterlab-chart-editor v1.2.0 enabled ok
jupyterlab-plotly v1.1.0 enabled ok
plotlywidget v1.1.0 enabled ok
Upvotes: 18
Views: 19849
Reputation: 10184
For anyone still struggling to make this work – these steps worked for me:
jupyter lab
from terminal again. Now you should see a window Build recommended – jupyterlab-dash needs to be included in build
. Confirm this.Upvotes: 0
Reputation: 408
Try installing jupyterlab dash, it worked for me!
you can do it through the jupyterlab menu or by following these instructions.
https://github.com/plotly/jupyter-dash
It looks like you should upgrade your plotly as well, because plotly express is now part of plotly i.e.
import plotly.express as px
Upvotes: 0
Reputation: 116
I ran into the same problem but with a different cause and requiring a different solution. Just thought I'd share it for anyone encountering the same issue.
I'm running jupyterlab in a Docker container which did not yet have nodejs or npm installed.
I was unable to install the required extension via:
jupyter labextension install jupyterlab-plotly
Because it gave me this error:
ValueError: Please install nodejs and npm before continuing installation. nodejs may be installed using conda or directly from the nodejs website.
Conda was not available on the container and when installing node and npm via the jupyterlab terminal (through pip or apt-get) I got the same error, or a version mismatch (when using apt-get the nodejs version I got was too old).
The following steps helped me solve the problem.
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
SHELL ["bash", "-lc"]
<-- Only necessary if your container is not using bash as shell alreadyRUN export NVM_DIR="$HOME/.nvm"
RUN [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
RUN [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
RUN nvm install 14.17.0
RUN jupyter labextension install jupyterlab-plotly
Restart the kernel and happy plotting ;)
You might also consider installing conda and then nodejs via conda if that makes sense for your use case. I have not tested if that works though.
Upvotes: 2
Reputation: 113
Following the official plotly.py repo https://github.com/plotly/plotly.py, for correct rendering of plotly in JupyterLab there's a need to installing the special extension by command
jupyter labextension install [email protected]
Upvotes: 3
Reputation: 27370
EDIT: these instructions and more are now in our official Troubleshooting Guide!
It could be that remnants of previous installations or attempts at installation are causing issues. I recommend either starting with a clean install or uninstalling all Plotly modules (from both pip and conda!) and plotly-related jlab extensions, and then following the instructions here: https://plot.ly/python/getting-started/
Uninstalling the module is a matter of
conda uninstall plotly
pip uninstall plotly
And then reinstalling with one or the other but not both, according to the instructions linked above.
Uninstalling JupyterLab extensions is performed with
jupyter labextension uninstall @jupyterlab/plotly-extension
jupyter labextension uninstall jupyterlab-plotly
jupyter labextension uninstall plotlywidget
Upvotes: 10