From 605a5156465f21b2f4530a370db66c221c1d8e20 Mon Sep 17 00:00:00 2001 From: Kevin Eger Date: Wed, 21 Jan 2026 18:15:59 +0000 Subject: [PATCH] Set the 'colab' renderer only for Colab web notebooks 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 https://github.com/plotly/plotly.py/issues/5471. --- plotly/io/_renderers.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plotly/io/_renderers.py b/plotly/io/_renderers.py index 4c21760bb0a..8eea1fe8bf8 100644 --- a/plotly/io/_renderers.py +++ b/plotly/io/_renderers.py @@ -488,13 +488,10 @@ def show(fig, renderer=None, validate=True, **kwargs): elif ipython and ipython.get_ipython(): # Try to detect environment so that we can enable a useful # default renderer - if not default_renderer: - try: - import google.colab # noqa: F401 - default_renderer = "colab" - except ImportError: - pass + # Check if we're running in a Colab web notebook + if not default_renderer and "COLAB_NOTEBOOK_ID" in os.environ: + default_renderer = "colab" # Check if we're running in a Kaggle notebook if not default_renderer and os.path.exists("/kaggle/input"):