plotly / plotly/plotly.py

[BUG]: Blank plot in Jupyterlab when plotly is installed in different virtual env from jupyter server

未关闭
#5,664 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P3 size: 3
主要语言
Python
星标
18.8k
派生
2.8k
平均合并
16 小时 26 分钟
30 天内合并 PR
21

描述

Description

I am using plotly in an environment managed by JupyterHub. I created a fresh virtual environment (independent from the one managed by JH, which I don't want to modify). I installed plotly in that virtual environment and added it as a kernel to Jupyter by running ipython kernel install in the virtual environment. However, if I open a Jupyter notebook with this kernel and try to create a plot, I get a blank figure. There is no Javascript error in the browser console.

Screenshots/Video
Image
Steps to reproduce

This can be reproduced by creating a clean virtual environment with only Jupyter in it and then another one which contains plotly:

mkdir /tmp/plotly-issue
cd /tmp/plotly-issue

# ~equivalent to the environment managed by JupyterHub
uv init --bare jupyter-env
cd jupyter-env
uv add jupyterlab

cd ..
uv init --bare kernel-env
cd kernel-env
uv add ipykernel plotly nbformat # "Mime type rendering requires nbformat"
uv run ipython kernel install --prefix /tmp/plotly-issue/jupyter-env/.venv/ --name kernel-with-plotly

cd ../jupyter-env
uv run jupyter lab

Then, in jupyterlab, create a new notebook with the kernel kernel-with-plotly and run

from plotly import graph_objects as go
fig = go.Figure()
fig.add_trace(go.Bar(x=[1, 2, 3], y=[1, 3, 2]))
fig.show()
Notes

The figure works correctly if I replace the last line with fig.show(renderer="notebook"). However, the blank figure was very confusing and it took me several hours to find this solution. Additionally, I found a lot of online discussion pointing to this troubleshooting page: https://plotly.com/python/troubleshooting/ which mentions Jupyter / Jupyterlab in the introduction, but there is no section related to Jupyter in the main text. I think this page should be updated with some additional information on Jupyter.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用两个 uv 环境以及通过 ipython kernel install 安装的内核重现空白图,然后比较默认的 fig.show()fig.show(renderer="notebook")。先从 issue 中描述的 Jupyter 相关行为和链接的 Plotly 故障排除页面开始。完成标准是默认显示在彼此独立的环境中都能正常工作,或者故障排除文档清楚说明所需的设置和变通方案。

由索引模型根据 Issue 内容生成。

评估

技术栈
jupyter-notebook, python
领域
data-visualization, documentation
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
52/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。