Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add selfcontained option to save_html() #73

Open
timelyportfolio opened this issue Nov 22, 2016 · 8 comments
Open

Add selfcontained option to save_html() #73

timelyportfolio opened this issue Nov 22, 2016 · 8 comments
Assignees
Milestone

Comments

@timelyportfolio
Copy link

timelyportfolio commented Nov 22, 2016

I could have easily missed an easier solution, but saving a tagList especially as selfcontained = TRUE seems difficult. Here is the function I wrote to accomplish this using bits and pieces of htmltools. Would this be deemed as something worth of htmltools?

save_tags <- function (tags, file, selfcontained = F, libdir = "./lib") 
{
    if (is.null(libdir)) {
        libdir <- paste(tools::file_path_sans_ext(basename(file)), 
            "_files", sep = "")
    }
    htmltools::save_html(tags, file = file, libdir = libdir)
    if (selfcontained) {
        if (!htmlwidgets:::pandoc_available()) {
            stop("Saving a widget with selfcontained = TRUE requires pandoc. For details see:\n", 
                "https://github.com/rstudio/rmarkdown/blob/master/PANDOC.md")
        }
        htmlwidgets:::pandoc_self_contained_html(file, file)
        unlink(libdir, recursive = TRUE)
    }
    return(file)
}
@timelyportfolio timelyportfolio changed the title save_tags function save tags or tagList function Nov 22, 2016
@cpsievert

This comment was marked as off-topic.

@cpsievert

This comment was marked as off-topic.

@cpsievert
Copy link
Collaborator

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

@cpsievert cpsievert added this to the Next release milestone Dec 7, 2022
@cpsievert cpsievert changed the title save tags or tagList function Add selfcontained option to save_html() Dec 13, 2022
@cpsievert
Copy link
Collaborator

cpsievert commented Dec 13, 2022

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()

@cderv
Copy link
Contributor

cderv commented Jan 5, 2023

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} rstudio/rmarkdown#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.

@cpsievert
Copy link
Collaborator

@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

@cderv
Copy link
Contributor

cderv commented Feb 8, 2023

Yes it feels to me general enough. We have rstudio/rmarkdown#2087 for rmarkdown function, so we need to rewrite this function. I agree.

@cpsievert cpsievert self-assigned this Feb 15, 2023
@aloboa
Copy link

aloboa commented Nov 1, 2023

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

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

No branches or pull requests

4 participants