Plotly express is not rendered in jupyter lab
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
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]
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.
- Install nvm in the docker container when building the container, thus in the Dockerfile:
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
- Mind the version number, you might want to change that to whatever is the latest stable version
- Make the nvm command available by loading some included init scripts:
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
- Install a specific nodejs version via nvm:
RUN nvm install 14.17.0
- Mind the version number again, change to whatever version you need.
- Install the jupyter extension:
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.