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

This patch allows htmlwidgets to display in pkgdown sites. #404

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ Imports:
yaml
Suggests:
knitr (>= 1.8),
downlit,
pkgdown,
rmarkdown,
testthat
Enhances: shiny (>= 1.1)
URL: https://github.com/ramnathv/htmlwidgets
BugReports: https://github.com/ramnathv/htmlwidgets/issues
RoxygenNote: 7.1.1
Remotes: dmurdoch/downlit@rglpatch, dmurdoch/pkgdown@rglpatch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have these PRs been merged? If so, the Remotes can be updated to point to the main repositories.

4 changes: 3 additions & 1 deletion R/knitr-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ registerMethods <- function(methods) {
# htmlwidgets and knitr are loaded.
registerMethods(list(
# c(package, genname, class)
c("knitr", "knit_print", "htmlwidget")
c("knitr", "knit_print", "htmlwidget"),
c("downlit", "replay_html", "htmlwidget"),
c("pkgdown", "pkgdown_print", "htmlwidget")
))
}

Expand Down
14 changes: 14 additions & 0 deletions R/pkgdown.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# These methods allow htmlwidget displays to appear in pkgdown
# web sites.

replay_html.htmlwidget <- function(x, ...) {
rendered <- htmltools::renderTags(x)
structure(rendered$html, dependencies = rendered$dependencies)
}

pkgdown_print.htmlwidget <- function(x, visible = TRUE) {
if (visible)
x
else
invisible(NULL)
}
8 changes: 8 additions & 0 deletions R/sizing.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ resolveSizing <- function(x, sp, standalone, knitrOptions = NULL) {
width = x$width %||% figWidth %||% any_prop(knitrScopes, "defaultWidth") %||% DEFAULT_WIDTH,
height = x$height %||% figHeight %||% any_prop(knitrScopes, "defaultHeight") %||% DEFAULT_HEIGHT
))
} else if (requireNamespace("pkgdown", quietly = TRUE) &&
pkgdown::in_pkgdown() &&
"fig_settings" %in% getNamespaceExports("pkgdown")) {
settings <- pkgdown::fig_settings()
return(list(
width = x$width %||% with(settings, fig.width*dpi) %||% DEFAULT_WIDTH,
height = x$height %||% with(settings, fig.height*dpi) %||% DEFAULT_HEIGHT
))
} else {
# Some non-knitr, non-print scenario.
# Just resolve the width/height vs. defaultWidth/defaultHeight
Expand Down