Skip to content

Set the 'colab' renderer only for Colab web notebooks#5473

Open
kevineger wants to merge 3 commits intoplotly:mainfrom
kevineger:colab
Open

Set the 'colab' renderer only for Colab web notebooks#5473
kevineger wants to merge 3 commits intoplotly:mainfrom
kevineger:colab

Conversation

@kevineger
Copy link
Copy Markdown

@kevineger kevineger commented Jan 21, 2026

Full context in #5471.

The current implementation detects if the google.colab module is available. This has a couple problems:

  1. Anyone can install that library, outside of Colab.
  2. The recently launched Colab VS Code extension does not work with that web-based renderer.

Snapping to the conventions used for the other notebooks/renderers (e.g. Kaggle, Azure), this change now looks for the presence of the COLAB_NOTEBOOK_ID environment variable. I'm an engineer on Colab and have verified that we set this on kernel init for all notebooks accessed through our web app (https://colab.research.google.com/).

Code PR

  • I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the code generator and not the generated files.
  • I have added tests or modified existing tests.
    • Added test.
    • Added regression test for old import approach.
  • For a new feature, I have added documentation examples (please see the doc checklist as well).
    • Not a new feature.
  • I have added a CHANGELOG entry if changing anything substantial.
    • Added, as requested.
  • For a new feature or a change in behavior, I have updated the relevant docstrings in the code.
    • Not a substantial feature change. I can update any docs if requested.

@kevineger
Copy link
Copy Markdown
Author

Hey @robertclaus and @camdecoster - mind taking a look or re-assigning? Let me know if any further action's needed on my end to move this along.

Thanks and sorry for the nag!

@camdecoster
Copy link
Copy Markdown
Contributor

@kevineger could you give me some instructions for how to test this? I'm not familiar with the Colab extension.

@kevineger
Copy link
Copy Markdown
Author

@kevineger could you give me some instructions for how to test this? I'm not familiar with the Colab extension.

@camdecoster you could package this up and run a local Colab runtime (docs).

The current implementation detects if the `google.colab` module is available. This has a couple problems:

1. Anyone can install that library, outside of Colab.
2. The recently launched [Colab VS Code extension](https://marketplace.visualstudio.com/items?itemName=Google.colab) does not work with that web-based renderer.

Snapping to the conventions used for the other notebooks/renderers (e.g. Kaggle, Azure), this change now looks for the presence of the `COLAB_NOTEBOOK_ID` environment variable. I'm an engineer on Colab and have verified that we set this on kernel init for all notebooks accessed through our web app (https://colab.research.google.com/).

More context in plotly#5471.
Copy link
Copy Markdown
Contributor

@camdecoster camdecoster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevineger I verified your changes work for setting the renderer when the COLAB_NOTEBOOK_ID env var is present. Before this gets merged, could you please add a test in tests/test_io/test_renderers.py? After that's done, could you tag me in a comment?

EDIT: Could you also please add a changelog entry?

@kevineger
Copy link
Copy Markdown
Author

Done and done @camdecoster ✔️

Let me know if there's a better way to test than what I did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants