绘制图不会在安装了零到JupyterHubGKE的JupyterLab上呈现

问题描述

我试图在JupyterLab上渲染Plotly图,并将其安装到GKE上的JupyterHub上为零。我在这里关注了文档:

https://plotly.com/python/getting-started/

但是,图形仍然不能直接在JupyterLab上呈现。还有其他我想念的东西吗?

感谢您的帮助!

解决方法

找到答案后,您实际上必须在该过程中再添加几个步骤。这是完整的:

  1. 按图安装pip install plotly==4.9.0
  2. 安装/升级Jupyterlab小部件pip install jupyterlab "ipywidgets>=7.5"
  3. 安装jupyterlab扩展jupyter labextension install [email protected]
  4. 可选jupyter labextension install @jupyter-widgets/jupyterlab-manager [email protected]
  5. 可选,检查安装的扩展程序jupyter labextension list
  6. 刷新jupyterlab的页面
  7. 通过运行jupyter lab build
  8. 构建映像

现在您可以打开笔记本并运行一些示例绘图代码:

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

您应该看到图形出现;)

,

一个似乎可行的简单解决方案是:

import plotly.graph_objects as go

fig = go.Figure(data=go.Bar(y=[2,1]))

fig.show(renderer="iframe")

它看起来也很好