Skip to content

Fix Bokeh in Colab #153

Merged
stared merged 2 commits intomainfrom
i109-bokeh-colab
May 4, 2026
Merged

Fix Bokeh in Colab #153
stared merged 2 commits intomainfrom
i109-bokeh-colab

Conversation

@stared
Copy link
Copy Markdown
Owner

@stared stared commented May 4, 2026

Fixes #109 (wow, I had lost hope on this one)

Screenshot 2026-05-04 at 13 48 03

stared and others added 2 commits May 4, 2026 13:12
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Bokeh's push_notebook is permanently dead in Colab — Google blocks
Jupyter Comms (bokeh#9302, colabtools#217). Detect Colab via
'google.colab' in sys.modules and take a separate render path:

  - Render the gridplot to a self-contained HTML doc via
    bokeh.embed.file_html with CDN resources.
  - Wrap it in <iframe srcdoc="..."> so DOM lookups inside the
    BokehJS bootstrap find their sibling JSON-data element (Colab's
    output handling fragments inline scripts from sibling DOM,
    which broke a flat-HTML attempt with a "Cannot read properties
    of null (reading 'textContent') at embed_document" error).
  - Display via IPython display(..., display_id=True) and update
    the same handle on subsequent send() calls — update_display_data
    is atomic, so the iframe is replaced cleanly with no flicker.

Also drops the notebook_type='colab' kwarg from output_notebook;
Bokeh 3.x removed that hook and raises RuntimeError if passed.
Modern Bokeh auto-detects Colab in plain output_notebook().

Includes examples/bokeh_colab.ipynb that installs livelossplot from
this branch on GitHub for in-Colab verification.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@stared stared force-pushed the i109-bokeh-colab branch from f522938 to c66aafe Compare May 4, 2026 11:51
@stared stared merged commit aa74c64 into main May 4, 2026
6 checks passed
@stared stared deleted the i109-bokeh-colab branch May 4, 2026 11:56
@stared stared changed the title [WIP] Fix Bokeh in Colab Fix Bokeh in Colab May 4, 2026
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.

Bokeh vis not working in Colab

1 participant