Better htmlwidget support#1215
Conversation
…red from the console
…enc dependency clear, improve tests
DavisVaughan
left a comment
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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/)"
)…ines, and force rendering in cases the onLoad has fired before the scripts are inserted
|
The related positron PR is posit-dev/positron#14150 This PR now handles a range of separate issues related to inline rendering of html widgets in quarto, the positron notebook and VS code notebook. A summary of the changes are:
|
DavisVaughan
left a comment
There was a problem hiding this comment.
Combined with the Positron side PR, the two examples mentioned above work for me now in both a Quarto file with inline output enabled, and a ipynb file.
I can't comment much on the AMD bits or the forced staticRender() call for htmlwidgets, but if it seems required then sounds good.
| @@ -3025,3 +3025,15 @@ pub unsafe extern "C-unwind" fn ps_get_active_request() -> anyhow::Result<SEXP> | |||
| let r_obj = RObject::try_from(json)?; | |||
There was a problem hiding this comment.
Still seeing the weird font issue in the pop out, probably want to at least open an issue for this.
i have a gut feeling the font thing is because in
quartoOutputManager.tsin_openWebviewInViewer(which is what the popout button calls) it also doescreateNotebookOutputWebview, which may need to transition to the "raw" html version too (i.e. tocreateRawHtmlOutputWebview)
Screen.Recording.2026-06-08.at.10.27.10.AM.mov
| head_parts <- c( | ||
| '<meta charset="utf-8"/>', | ||
| AMD_GUARD_OPEN, | ||
| dep_html, | ||
| rendered$head | ||
| ) | ||
|
|
||
| paste0( | ||
| "<!DOCTYPE html>\n", | ||
| "<html>\n", | ||
| "<head>\n", | ||
| paste(head_parts, collapse = "\n"), |
There was a problem hiding this comment.
the amd_guard_open goes in the <head> but the amd_guard_close is outside of it? i dont know anything about this, it just smells odd
| // Defensive reset in case a sibling test leaked the option. | ||
| code.push_str("options(ark.html_widget.deduplicate = NULL)\n"); |
There was a problem hiding this comment.
I think you should remove all of these "defensive resets"
With nextest, all Rust tests run in their own individual process, so this is a non issue and will only confuse future us
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