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

prefer webshot2 to webshot and solve #1858 #1918

Merged
merged 6 commits into from
Jan 29, 2021
Merged
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Fixed an issue with `kable(format = "latex", booktabs = TRUE)` when the first cell of the table stats with `[` (thanks, @jonnypenarth, #1595).

- The internal `html_screenshot` prefers the **webshot2** package to the **webshot** package. This is because backend of the **webshot** package is phantom.js, which is the archived project since 2018 (<https://github.com/ariya/phantomjs/issues/15344>). If **webshot** is preferred, run `opts_chunk$set(webshot = "webshot")` (thanks, @atusy, #1918).

# CHANGES IN knitr VERSION 1.31

## NEW FEATURES
Expand Down
21 changes: 16 additions & 5 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -511,18 +511,27 @@ need_screenshot = function(x, ...) {
if (length(fmt) == 0 || force) return(i1 || i2 || i3)
html_format = fmt %in% c('html', 'html4', 'html5', 'revealjs', 's5', 'slideous', 'slidy')
res = ((i1 || i3) && !html_format) || (i2 && !(html_format && runtime_shiny()))
res && webshot_available()
res && any(webshot_available())
}

runtime_shiny = function() {
identical(opts_knit$get('rmarkdown.runtime'), 'shiny')
}

webshot_available = local({
res = NULL # cache the availablity of webshot/PhantomJS
res = NULL # cache the availablity of webshot2 and webshot/PhantomJS
function() {
if (is.null(res))
res <<- loadable('webshot') && !is.null(getFromNamespace('find_phantom', 'webshot')())
res <<- c(
webshot2 = (
loadable('webshot2') &&
tryCatch(
file.exists(getFromNamespace('find_chrome', 'chromote')()),
error = function(e) FALSE
)
),
webshot = loadable('webshot') && !is.null(getFromNamespace('find_phantom', 'webshot')())
)
res
}
})
Expand Down Expand Up @@ -550,18 +559,20 @@ html_screenshot = function(x, options = opts_current$get(), ...) {
if (is.null(wargs$delay)) wargs$delay = if (i1) 0.2 else 1
d = tempfile()
dir.create(d); on.exit(unlink(d, recursive = TRUE), add = TRUE)
w = webshot_available()
webshot = c(options$webshot, names(w)[w])[[1L]]
f = in_dir(d, {
if (i1 || i3) {
if (i1) {
f1 = wd_tempfile('widget', '.html')
save_widget(x, f1, FALSE, options = options)
} else f1 = x$url
f2 = wd_tempfile('webshot', ext)
f3 = do.call(webshot::webshot, c(list(f1, f2), wargs))
f3 = do.call(getFromNamespace('webshot', webshot), c(list(f1, f2), wargs))
normalizePath(f3)
} else if (i2) {
f1 = wd_tempfile('webshot', ext)
f2 = do.call(webshot::appshot, c(list(x, f1), wargs))
f2 = do.call(getFromNamespace('appshot', webshot), c(list(x, f1), wargs))
normalizePath(f2)
}
})
Expand Down