Context
When Plotly uses non-default renderers (notebook, iframe_connected), it emits text/html output containing <script> tags that reference window.Plotly or require('plotly'). Currently, plotly.js is only injected into iframes when application/vnd.plotly.v1+json is detected in the output MIME types.
This means text/html Plotly outputs from these backends silently fail — the scripts execute but window.Plotly is undefined.
Possible Approach
Scan text/html output content for known Plotly signatures (e.g., Plotly.newPlot, require(['plotly'], require("plotly")) before rendering. If detected, inject plotly.js into the iframe before the HTML is rendered.
This would be similar to how getRequiredLibraries() scans MIME types today, but extended to peek at HTML content for known library references.
Notes
Context
When Plotly uses non-default renderers (
notebook,iframe_connected), it emitstext/htmloutput containing<script>tags that referencewindow.Plotlyorrequire('plotly'). Currently, plotly.js is only injected into iframes whenapplication/vnd.plotly.v1+jsonis detected in the output MIME types.This means
text/htmlPlotly outputs from these backends silently fail — the scripts execute butwindow.Plotlyis undefined.Possible Approach
Scan
text/htmloutput content for known Plotly signatures (e.g.,Plotly.newPlot,require(['plotly'],require("plotly")) before rendering. If detected, inject plotly.js into the iframe before the HTML is rendered.This would be similar to how
getRequiredLibraries()scans MIME types today, but extended to peek at HTML content for known library references.Notes
plotly_mimetyperenderer outputsapplication/vnd.plotly.v1+jsonwhich works correctly via the renderer plugin APIcdnrenderer which includes a CDN<script>tag) already work