diff --git a/R/knitr.R b/R/knitr.R index 339c45db6..e404638d1 100644 --- a/R/knitr.R +++ b/R/knitr.R @@ -258,7 +258,11 @@ fns <- local({ left = "margin-left:0;margin-right:auto;", right = "margin-left:auto;margin-right:0;", "")))) - result <- do.call("knit_print", c(list(content, options), x$args)) + # Not sure why this wasn't there for our vignettes... + if (!("screenshot.force" %in% names(options))) + options$screenshot.force <- FALSE + + result <- do.call("knit_print", c(list(x = content, options = options), x$args)) if (!latex) class(result) <- c(class(result), "knit_asis_htmlwidget") diff --git a/R/rglwidget.R b/R/rglwidget.R index 6d921c4a8..6246b9709 100644 --- a/R/rglwidget.R +++ b/R/rglwidget.R @@ -241,12 +241,25 @@ asRow <- function(..., last = NA, height = NULL, colsize = 1) { newElementId <- function(prefix) paste0(prefix, p_sample(100000, 1)) +isMarkdownHTMLformat <- function() { + output <- rmarkdown::metadata$output + + if (is.list(output)) + output <- names(output) + + is.character(output) && + length(output) >= 1 && + output[1] == "markdown::html_format" +} + knitrNeedsSnapshot <- function(options = knitr::opts_current$get()) { if (!is.null(options$snapshot)) return(options$snapshot) if (isFALSE(options$screenshot.force)) return(FALSE) force <- isTRUE(options$screenshot.force) + if (isMarkdownHTMLformat()) + return(FALSE) fmt <- pandoc_to() if (!length(fmt) || force) return(TRUE) diff --git a/man/snapshot.Rd b/man/snapshot.Rd index 4b27792bc..461e06ef6 100644 --- a/man/snapshot.Rd +++ b/man/snapshot.Rd @@ -29,10 +29,13 @@ Ignored if \code{webshot = TRUE}.} \details{ \code{rgl.snapshot()} is a low-level function that copies the current RGL window from the screen. Users -should use \code{snapshot3d()} instead; it is more flexible, +should usually use \code{snapshot3d()} instead; it is more flexible, and (if \pkg{webshot2} is installed) can take images even if no window is showing, and they can be larger than the physical -screen. +screen. On some systems \pkg{webshot2} doesn't work reliably; if +you find \code{snapshot3d()} failing or taking a very long time +I'd recommend using \code{snapshot3d(..., webshot = FALSE)}. See +the note below about \code{RGL_USE_WEBSHOT} to make this the default. Animations can be created in a loop modifying the scene and saving each screenshot to a file. Various graphics programs (e.g. ImageMagick) diff --git a/vignettes/demos.Rmd b/vignettes/demos.Rmd index 475a53171..4368aafd6 100644 --- a/vignettes/demos.Rmd +++ b/vignettes/demos.Rmd @@ -14,7 +14,9 @@ vignette: > ```{r setup, include = FALSE} knitr::opts_chunk$set( collapse = FALSE, # Bug in knitr 1.42 requires FALSE here - comment = "#>") + comment = "#>", + snapshot = FALSE, + screenshot.force = FALSE) library(rgl) setupKnitr(autoprint = TRUE) ``` diff --git a/vignettes/pkgdown.Rmd b/vignettes/pkgdown.Rmd index fb5d1169e..5ed76a19c 100644 --- a/vignettes/pkgdown.Rmd +++ b/vignettes/pkgdown.Rmd @@ -25,7 +25,7 @@ if (!requireNamespace("rmarkdown", quietly = TRUE)) { warning(call. = FALSE, "These vignettes assume rmarkdown. This was not found.") knitr::knit_exit() } -knitr::opts_chunk$set(echo = TRUE) +knitr::opts_chunk$set(echo = TRUE, snapshot = FALSE, screenshot.force = FALSE) library(rgl) options(rgl.useNULL = TRUE) setupKnitr(autoprint = TRUE) diff --git a/vignettes/setup.R b/vignettes/setup.R index 62261c6c2..9ffc67947 100644 --- a/vignettes/setup.R +++ b/vignettes/setup.R @@ -14,7 +14,7 @@ if (!requireNamespace("rmarkdown", quietly = TRUE)) { # knitr uses it to determine whether to do # screenshots; we don't want those. see https://github.com/rstudio/markdown/issues/115 -knitr::opts_knit$set(screenshot.force = FALSE) +knitr::opts_chunk$set(screenshot.force = FALSE, snapshot = FALSE) # knitr::opts_chunk$set(snapshot = TRUE) # for snapshots instead of dynamic diff --git a/vignettes/transparency.Rmd b/vignettes/transparency.Rmd index 4b5d0f9ca..cbaa7afde 100644 --- a/vignettes/transparency.Rmd +++ b/vignettes/transparency.Rmd @@ -26,7 +26,7 @@ if (!requireNamespace("rmarkdown", quietly = TRUE)) { warning(call. = FALSE, "These vignettes assume rmarkdown is installed. This was not found.") knitr::knit_exit() } -knitr::opts_chunk$set(echo = TRUE) +knitr::opts_chunk$set(echo = TRUE, snapshot = FALSE, screenshot.force = FALSE) library(rgl) options(rgl.useNULL = TRUE) setupKnitr(autoprint = TRUE)