Skip to content

Commit

Permalink
Work hard to avoid webshot2 screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
dmurdoch committed Jul 7, 2024
1 parent a53d75c commit 4d15a33
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
6 changes: 5 additions & 1 deletion R/knitr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
13 changes: 13 additions & 0 deletions R/rglwidget.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions man/snapshot.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion vignettes/demos.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
Expand Down
2 changes: 1 addition & 1 deletion vignettes/pkgdown.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion vignettes/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion vignettes/transparency.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4d15a33

Please sign in to comment.