Skip to content

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

@jmcphers

Description

@jmcphers

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 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 (which does support HTML widgets in notebooks). Less performant, probably, but more self-contained.
  • Map Jupyter's "ipywidgets" concept 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

This is required for HTML widgets to work correctly in both notebooks (posit-dev/positron#4219) and Quarto inline outputs (posit-dev/positron#5640).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions