coatless / quarto-webr

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

[Feature]: Support `htmlwidgets` #222

Closed dipterix closed 1 month ago

dipterix commented 2 months 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 2 months ago

Here's an example with the PR:

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

coatless commented 2 months 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 month ago

Would love to see this feature integrated too!

coatless commented 1 month ago

Closed by #223

Note, we probably want to incorporate save_selfcontained() proposed by timelyportfolio inside of qwebr but we'll leave that for a second follow-up.

dipterix commented 1 month ago

Thanks, this is great!