Skip to content

Commit bf4b03e

Browse files
committed
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 #5471.
1 parent 10c7c56 commit bf4b03e

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

plotly/io/_renderers.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,13 +488,10 @@ def show(fig, renderer=None, validate=True, **kwargs):
488488
elif ipython and ipython.get_ipython():
489489
# Try to detect environment so that we can enable a useful
490490
# default renderer
491-
if not default_renderer:
492-
try:
493-
import google.colab # noqa: F401
494491

495-
default_renderer = "colab"
496-
except ImportError:
497-
pass
492+
# Check if we're running in a Colab web notebook
493+
if not default_renderer and "COLAB_NOTEBOOK_ID" in os.environ:
494+
default_renderer = "colab"
498495

499496
# Check if we're running in a Kaggle notebook
500497
if not default_renderer and os.path.exists("/kaggle/input"):

0 commit comments

Comments
 (0)