{"action":"created","issue":{"url":"https://api.github.com/repos/ramnathv/htmlwidgets/issues/146","labels_url":"https://api.github.com/repos/ramnathv/htmlwidgets/issues/146/labels{/name}","comments_url":"https://api.github.com/repos/ramnathv/htmlwidgets/issues/146/comments","events_url":"https://api.github.com/repos/ramnathv/htmlwidgets/issues/146/events","html_url":"https://github.com/ramnathv/htmlwidgets/issues/146","id":100125147,"number":146,"title":"Allow self-contained knitr_print","user":{"login":"elbamos","id":10103420,"avatar_url":"https://avatars.githubusercontent.com/u/10103420?v=3","gravatar_id":"","url":"https://api.github.com/users/elbamos","html_url":"https://github.com/elbamos","followers_url":"https://api.github.com/users/elbamos/followers","following_url":"https://api.github.com/users/elbamos/following{/other_user}","gists_url":"https://api.github.com/users/elbamos/gists{/gist_id}","starred_url":"https://api.github.com/users/elbamos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elbamos/subscriptions","organizations_url":"https://api.github.com/users/elbamos/orgs","repos_url":"https://api.github.com/users/elbamos/repos","events_url":"https://api.github.com/users/elbamos/events{/privacy}","received_events_url":"https://api.github.com/users/elbamos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-08-10T17:35:45Z","updated_at":"2015-08-10T22:32:56Z","closed_at":null,"body":"I'm trying to make it possible to embed htmlwidgets in a larger project using knitr.  It seems that the knitr_print function for HTML widgets sets standalone=false, which makes it a lot harder to embed. Is it possible to change this so it pulls standalone from an option or from the chunk options? Or is FALSE hardcoded because that just won't work?"},"comment":{"url":"https://api.github.com/repos/ramnathv/htmlwidgets/issues/comments/129634799","html_url":"https://github.com/ramnathv/htmlwidgets/issues/146#issuecomment-129634799","issue_url":"https://api.github.com/repos/ramnathv/htmlwidgets/issues/146","id":129634799,"user":{"login":"elbamos","id":10103420,"avatar_url":"https://avatars.githubusercontent.com/u/10103420?v=3","gravatar_id":"","url":"https://api.github.com/users/elbamos","html_url":"https://github.com/elbamos","followers_url":"https://api.github.com/users/elbamos/followers","following_url":"https://api.github.com/users/elbamos/following{/other_user}","gists_url":"https://api.github.com/users/elbamos/gists{/gist_id}","starred_url":"https://api.github.com/users/elbamos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elbamos/subscriptions","organizations_url":"https://api.github.com/users/elbamos/orgs","repos_url":"https://api.github.com/users/elbamos/repos","events_url":"https://api.github.com/users/elbamos/events{/privacy}","received_events_url":"https://api.github.com/users/elbamos/received_events","type":"User","site_admin":false},"created_at":"2015-08-10T22:32:56Z","updated_at":"2015-08-10T22:32:56Z","body":"Actually just to make sure — would it use that automatically inside of a knitr chunk?  And is it self-contained?\n\n\nFrom: AMOS ELBERG <amos.elberg@me.com>\nReply: AMOS ELBERG <amos.elberg@me.com>\nDate: August 10, 2015 at 5:50:45 PM\nTo: ramnathv/htmlwidgets <reply@reply.github.com>\nCc: ramnathv/htmlwidgets <htmlwidgets@noreply.github.com>\nSubject:  Re: [htmlwidgets] Allow self-contained knitr_print (#146)  \n\nLooks perfect to me! How can I help?\n\nThanks!\n\nOn Aug 10, 2015, at 5:29 PM, Ramnath Vaidyanathan <notifications@github.com> wrote:\n\nWell you can embed iframes inline using the srcref attribute. The downside is that it doesn't work in all browsers. Based on what you indicated, it seems to me that what we need is a modified version of htmltools::save_html, which is the underlying force behind htmlwidgets::saveWidget.\n\nsave_html = function (html, file, libdir = \"lib\") {\n    dir <- dirname(file)\n    oldwd <- setwd(dir)\n    on.exit(setwd(oldwd), add = TRUE)\n    rendered <- renderTags(html)\n    deps <- lapply(rendered$dependencies, function(dep) {\n        dep <- copyDependencyToDir(dep, libdir, FALSE)\n        dep <- makeDependencyRelative(dep, dir, FALSE)\n        dep\n    })\n    html <- c(\"<!DOCTYPE html>\", \"<html>\", \"<head>\", \"<meta charset=\\\"utf-8\\\"/>\",  \n        renderDependencies(deps, c(\"href\", \"file\")), rendered$head,  \n        \"</head>\", \"<body>\", rendered$html, \"</body>\", \"</html>\")\n    writeLines(html, file, useBytes = TRUE)\n}\nBased on your description, seems like you need a htmltools:::save_html_fragment, that would modify the above function and write\n\nhtml <- c(renderDependencies(deps, c(\"href\", \"file\")), rendered$html, \"</body>\")\n\nYou would then need a modified version of htmlwidgets::saveWidget that calls htmltools::save_html_fragment instead of htmltools::save_html.\n\nIf you think this would work, I would be happy to add this functionality to htmlwidgets.\n\n—\nReply to this email directly or view it on GitHub.\n\n"}}