plotly / plotly/plotly.py

[BUG]: Plotly doesn't render properly when used in the Colab VS Code extension.

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

@kevineger 已经在做这个了。

开始于 2026年1月21日。

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

描述

Description

Hi there 👋, I'm the maintainer of the Colab VS Code extension which we recently launched:

One of our users reported https://github.com/googlecolab/colab-vscode/issues/339. Summarized, today Plotly doesn't render properly in VS Code when using the Colab extension. This requires users to manually configure the default renderer, instead of being able to lean on Plotly's detection.

Steps to reproduce
  • Install the Colab VS Code extension
  • Create a new Jupyter notebook file
  • Click Select Kernel
  • Select Colab
  • If prompted (first run), sign in to Google
  • Author a cell which renders a Plotly plot, e.g.:
    import plotly.express as px
    import pandas as pd
    import plotly.io as pio
    
    data = {'x': [1, 2, 3, 4, 5], 'y': [1, 2, 4, 8, 16], 'text': ['hello', 'world', '!', '!', '!']}
    df = pd.DataFrame(data)
    fig = px.scatter(df, x="x", y="y", text="text", title="Hello World Plotly Express")
    fig.update_traces(textposition='top center')
    fig.show()
    
  • Execute the cell

Expected behaviour: plot is rendered as it does if you set pio.renderers.default = "vscode" before showing the plot.

Actual behaviour: nothing is rendered. You can Copy cell output and see the HTML output that's returned instead. This works in web-based Colab.

Notes

As you'll see in my reply, this seems to be caused by this block in Plotly, where the default_renderer gets set to colab. If I set plotly.io.renderers.default to 'plotly_mimetype' or 'vscode', everything works as intended.

Unfortunately, VS Code doesn't set VSCODE_PID for these remote Colab kernels, so we can't simply re-order the default renderer checks. One possible solution is to extend the Colab check from only looking for import google.colab to also check for COLAB_NOTEBOOK_ID, which I believe (need to double check) is only set for web-based Colab. Feels a bit brittle. Open to suggestions, and happy to send a PR once we reach consensus!

贡献指南

打开贡献指南

从这里开始

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

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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