Skip to content

Better htmlwidget support#1215

Open
thomasp85 wants to merge 9 commits into
mainfrom
native-HTML-widget
Open

Better htmlwidget support#1215
thomasp85 wants to merge 9 commits into
mainfrom
native-HTML-widget

Conversation

@thomasp85

Copy link
Copy Markdown
Collaborator

Fix #1034

This PR adds proper htmlwidget support for notebooks and inline quarto content. It follows suggestion 2 from @jmcphers and inlines the html directly, like the IRKernel. The reasons for this is mainly that supporting Jupyter Widgets would be a substantial addition with no user-visible upside since the one thing it provides (bidirectional communication) isn't possible with htmlwidgets anyway. If a compelling use case for bidirectional communication comes up we can revisit it.

We don't need pandoc or any other heavy dependency because the html is trivial to construct.

One wrinkle is that IRKernel defaults to deduplicating html dependencies from consecutive cells. This facility also exist in this PR but since Positrons notebook view renders each cell in isolation. Due to that the default for ark is to not deduplicate.

All changes only has an effect for notebooks. The standard path for viewer/plot pane remains unchanged

@thomasp85 thomasp85 marked this pull request as draft May 13, 2026 21:11
@thomasp85 thomasp85 marked this pull request as ready for review May 21, 2026 07:42
@thomasp85 thomasp85 requested a review from DavisVaughan May 21, 2026 07:43

@DavisVaughan DavisVaughan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code all seems good, but i have not actually been able to get this feature to work for me yet

Ping me on slack if the examples below (i.e. leaflet) work for you and we can try to figure out what I'm doing wrong before merging

Comment thread crates/ark/src/viewer.rs Outdated
Comment thread crates/ark/src/viewer.rs Outdated
Comment thread crates/ark/src/modules/positron/html_widgets.R Outdated
Comment thread crates/ark/src/viewer.rs Outdated
Comment thread crates/ark/src/modules/positron/html_widgets.R Outdated
Comment thread crates/ark/src/modules/positron/html_widgets.R
Comment thread crates/ark/src/modules/positron/html_widgets.R
Comment thread crates/ark/src/modules/positron/html_widgets.R Outdated
Comment thread crates/ark/src/viewer.rs Outdated
Comment thread crates/ark/src/viewer.rs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to work?

library(leaflet)
m <- leaflet() %>% addTiles()
m

I tried it in a qmd with inline output turned on and got a blank output pane

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another one that doesn't work for me

library(billboarder)

# data
data("prod_par_filiere")

billboarder(data = prod_par_filiere) %>%
  bb_barchart(
    mapping = aes(x = annee, y = prod_hydraulique),
    color = "#102246"
  ) %>%
  bb_y_grid(show = TRUE) %>%
  bb_y_axis(
    tick = list(format = suffix("TWh")),
    label = list(
      text = "production (in terawatt-hours)",
      position = "outer-top"
    )
  ) %>%
  bb_legend(show = FALSE) %>%
  bb_labs(
    title = "French hydraulic production",
    caption = "Data source: RTE (https://opendata.reseaux-energies.fr/)"
  )

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.

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

2 participants