coatless / quarto-webr

Community developed Quarto Extension to Embed webR for HTML Documents, RevealJS, Websites, Blogs, and Books.
https://quarto-webr.thecoatlessprofessor.com/
380 stars 19 forks source link

[Feature]: Support `htmlwidgets` #222

Open dipterix opened 3 days ago

dipterix commented 3 days ago

Feature Description

Currently there is no support for htmlwidgets by quarto-webr.

I somehow managed to get it working. Here I would like to propose this method, hopefully it can be integrated into quarto-webr.

Basically there are two changed needed to visualize htmlwidgets via webr:

  1. The widget must be able to be saved as selfcontained
  2. quarto-webr needs to support browse type (introduced by webr::viewer_install()

For Step 1, users can use this work-around or wait for htmlwidgets to add this feature. Step 2 needs to be done from quarto-webr (see PR https://github.com/coatless/quarto-webr/pull/223).

library(dygraphs)
view <- function(widget) {
    webr::viewer_install()
    path <- save_selfcontained(v)
    getOption("viewer")(path)
}

v <- dygraph(nhtemp, main = "New Haven Temperatures") %>% 
  dyRangeSelector(dateWindow = c("1920-01-01", "1960-01-01"))
view(v)

image

dipterix commented 3 days ago

Here's an example with the PR:

https://rave.wiki/posts/3dviewer/viewer201.html

coatless commented 3 days ago

@dipterix thanks! I'll check out the PR tomorrow in more depth.

P.S. Woahza, that's a really nice embedding demo.

holtzy commented 1 hour ago

Would love to see this feature integrated too!