plotly / plotly/plotly.py

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

Đang mở
#5,471 3 bình luận 1 reaction 1 người được giao Xem trên GitHub

@kevineger đang làm issue này rồi.

Từ ngày 21/1/2026.

bug
Ngôn ngữ chính
Python
Star
18.8k
Fork
2.8k
Merge trung bình
16 giờ 26 phút
Pull request đã merge (30 ngày)
21

Mô tả

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!

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.