ITADN

In notebook mode, emit HTML widgets as static, embeddable HTML

#1034Openjmcphers 创建于 2026-02-10
area: jupyter kernel
J
jmcpherscommented
Currently HTML widgets are displayed in Positron as follows: - The widget is saved to a temporary directory, along with all its supporting files and libraries - The path is sent to Positron - Positron creates a lightweight proxy to serve files from the path - The URL to the proxy is shown in the Viewer pane This is great for interactive consoles; it is performant, can be cached, works similarly to deployed widgets, etc. But doesn't work at all for notebooks because the temporary files are ephemeral and don't get saved with the notebook. Consequently, we need to implement an alternate way to send HTML widgets to Positron when Ark is in notebook mode. There are a few ways we could address this: - Send a JSON representation of the widget data along with metadata listing all its dependencies, to be rendered statically by a [notebook output renderer](https://code.visualstudio.com/api/extension-guides/notebook#_notebook-renderer) in Positron. The data is rendered into HTML just in time using the htmlwidgets JS framework. (this was originally the approach I tried for HTML widgets in Positron proper) - Use pandoc or a similar tool to convert the entire widget into a single blob of HTML that can be sent to Positron. This is [the approach used by IRKernel](https://github.com/IRkernel/repr/blob/826281bc655f2cec4601a2d7aee3f63f76af97ec/R/repr_htmlwidget.r#L129) (which _does_ support HTML widgets in notebooks). Less performant, probably, but more self-contained. - Map [Jupyter's "ipywidgets" concept](https://ipywidgets.readthedocs.io/en/stable/) onto HTML widgets and write whatever bridge/glue code is needed, so HTML widgets appear as Jupyter/ipywidgets from Positron's perspective - [Run away from home and live in the woods](https://www.wikihow.com/Run-Away-from-Home-and-Live-in-the-Woods) This is required for HTML widgets to work correctly in both notebooks (https://github.com/posit-dev/positron/issues/4219) and Quarto inline outputs (https://github.com/posit-dev/positron/issues/5640).
3 条评论