Open timelyportfolio opened 7 years ago
IMO, yes, this could have a lot of impact. And ideally, the implementation would not depend on pandoc, but instead depend on the base64enc package.
Furthermore, it would be nice if there was an option to just return a character string of HTML (instead of always writing to disk). This would be especially useful for embedding tags/htmlwidgets in Jupyter/nteract/etc notebooks, for instance.
If I can get a 👍 from the maintainer, I may be able to find time for a prototype...
FWIW, I just implemented something related to this for Jupyter notebooks -- https://github.com/IRkernel/repr/blob/master/R/repr_htmlwidget.r
Maybe it makes sense to have renderDependencies()
have a self_contained
arg (which would base64 encode the dependencies), so other functions, like renderDocument()
can take advantage
What we should really do is basically copy https://github.com/ramnathv/htmlwidgets/blob/master/R/pandoc.R over to {htmltools}
(and use it to implement htmltools::save_html(selfcontained = TRUE)
which would mean htmlwidgets::saveWidget()
could be a simple wrapper around htmltools::save_html()
)
Also, when we copy over the implementation, we should look into using {pandoc}
over {rmarkdown}
for pandoc_available()
and pandoc_convert()
Just some thought about this
pandoc.R in htmlwidget seems to be adapted to work with rmarkdown::pandoc_self_contained_html
Forked from htmltools::save_html to work better with pandoc_self_contained_html
However, we need to revisit the function in {rmarkdown}
https://github.com/rstudio/rmarkdown/issues/2087, and maybe this is something to consider lower level and store in {pandoc}
I think we should try synchronize on this Carson when you think you'll tackle this.
@cderv I'm starting to look into this, and it does seem like having essentially the equivalent of
https://github.com/rstudio/rstudio/blob/0420c87/src/cpp/session/modules/ModuleTools.R#L375
(but with a sensible default for template
?) exported by {pandoc}
or {rmarkdown}
would indeed be quite useful for {htmltools}
(and thus {htmlwidgets}
). That said, I may just experiment with a version that's local to {htmltools}
for now and send you a PR (probably to {pandoc}
?) if it feels general enough
Yes it feels to me general enough. We have https://github.com/rstudio/rmarkdown/issues/2087 for rmarkdown function, so we need to rewrite this function. I agree.
Is there a planned date for implementing this feature? Meanwhile I'm using the suggested function (@ timelyportfolio thanks!), using rmarkdown::pandoc_available() and rmarkdown::pandoc_self_contained_html
I could have easily missed an easier solution, but saving a
tagList
especially asselfcontained = TRUE
seems difficult. Here is the function I wrote to accomplish this using bits and pieces ofhtmltools
. Would this be deemed as something worth ofhtmltools
?