Skip to content

Render Plotly Interactive Plot in Colab and Quarto #10263

@s2t2

Description

@s2t2

Bug description

I have an IPYNB file (notebook downloaded from Google Colab). It has a cell in it that makes a chart in plotly:

import plotly.express as px

fig = px.line(x=[1,2,3], y=[1,2,3])
fig.show()

I see the chart in the colab notebook, but not when I render that notebook as a source file for a Quarto project.

Plotly figures do get displayed when rendered from a .QMD file, but I want to use .IPYNB because my notebook has taken advantage of Colab-specific functionality, like forms, notebook secrets, etc.

My question is: how can I get plotly figures to be properly displayed in Quarto, using a .IPYNB file source, in such a way that will work BOTH in colab and in Quarto?

Here is some investigation code. It appears different renderers work on colab vs quarto, but there is no overlap?

The solution documented here does not render in colab:
https://quarto.org/docs/interactive/widgets/jupyter.html#plotly

pio.renderers.default = "colab+plotly_mimetype+notebook_connected"
fig.show()

Here is a notebook that shows the results of all renderer options in Colab. Only "colab" and "sphinx_gallery" renderers work in Colab. But they don't work in Quarto. We need one option that will work for both.

https://colab.research.google.com/drive/1UpmfA_Ybj8i4rDtgPnQz1af79STG2enP?usp=sharing

https://stackoverflow.com/questions/78694049/plotly-figures-not-displaying-in-quarto

Steps to reproduce

I have an IPYNB file (notebook downloaded from Google Colab). It has a cell in it that makes a chart in plotly:

import plotly.express as px

fig = px.line(x=[1,2,3], y=[1,2,3])
fig.show()

I see the chart in the colab notebook, but not when I render that notebook as a source file for a Quarto project.

Expected behavior

No response

Actual behavior

No response

Your environment

No response

Quarto check output

(quarto-env) --->> quarto check
Quarto 1.4.554
[✓] Checking versions of quarto binary dependencies...
Pandoc version 3.1.11: OK
Dart Sass version 1.69.5: OK
Deno version 1.37.2: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
Version: 1.4.554
Path: /Applications/quarto/bin

[✓] Checking tools....................OK
TinyTeX: (not installed)
Chromium: (not installed)

[✓] Checking LaTeX....................OK
Using: Installation From Path
Path: /usr/local/bin
Version: undefined

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
Version: 3.11.9 (Conda)
Path: /opt/anaconda3/envs/quarto-env/bin/python
Jupyter: 5.7.2
Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
Version: 4.3.1
Path: /usr/local/Cellar/r/4.3.1/lib/R
LibPaths:
- /usr/local/lib/R/4.3/site-library
- /usr/local/Cellar/r/4.3.1/lib/R/library
knitr: (None)
rmarkdown: (None)

  The knitr package is not available in this R installation.
  Install with install.packages("knitr")
  The rmarkdown package is not available in this R installation.
  Install with install.packages("rmarkdown")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions