我尝试在 JupyterLab 上渲染 Plotly 图表,该图表是通过 GKE 上的 Zero to JupyterHub 安装的。我按照此处的文档进行操作:
https://plotly.com/python/getting-started/
但是,图表仍然无法直接在 JupyterLab 上渲染。我还有什么遗漏的吗?
感谢您的帮助!
最佳答案
找到了答案,您实际上必须在该过程中添加更多步骤。完整内容如下:
- plotly 安装
pip install plotly==4.9.0
- 安装/升级 Jupyterlab 小部件
pip install jupyterlab "ipywidgets>=7.5"
- 安装 jupyterlab 扩展
jupyter labextension install <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="503a2520292435223c31327d203c3f243c2910647e697e60" rel="noreferrer noopener nofollow">[email protected]</a>
- 可选
jupyter labextension install @jupyter-widgets/jupyterlab-manager <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="84f4e8ebf0e8fdf3ede0e3e1f0c4b0aabdaab4" rel="noreferrer noopener nofollow">[email protected]</a>
- 可选,检查已安装的扩展
jupyter labextension list
- 刷新 jupyterlab 页面
- 通过运行
jupyter lab build
构建镜像
现在您可以打开笔记本并运行一些示例绘图代码:
import plotly.graph_objects as go
fig = go.Figure(data=go.Bar(y=[2, 3, 1]))
fig.show()
您应该看到出现的图表;)
关于Plotly 图表不会在使用 Zero To JupyterHub (GKE) 安装的 JupyterLab 上呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63449330/