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

Pass width and height dimension in percents #48

Open
cderv opened this issue Mar 3, 2023 · 1 comment
Open

Pass width and height dimension in percents #48

cderv opened this issue Mar 3, 2023 · 1 comment

Comments

@cderv
Copy link

cderv commented Mar 3, 2023

This comes from rstudio/rmarkdown#2460

In knitr we were using webshot but now default to webshot2 is installed on the user side so that we can do screenshots of html widgets to include in PDF for example. Dimensions for the screenshot is passed from value set in chunk options out.width and out.height converted in px units, except if passed in % that we keep. This means for such chunk

```{r}
#| out.height="100%"
library(plotly)
p <- plot_ly(economics, x = ~date, y = ~unemploy / pop)
p
```

this will be equivalent to passing vwidth = 468 and vheight = "100%.

Simulating that outside of knitr we get the error also

> webshot2::webshot("https://github.com/rstudio/shiny", vwidth = 468, vheight = "100%")
Error in s$close() : attempt to apply non-function
Full backtrace
<error/rlang_error>
Error in `s$close()`:
! attempt to apply non-function
---
Backtrace:
     ▆
  1. └─webshot2::webshot(...)
  2.   └─cm$wait_for(p)
  3.     └─chromote:::synchronize(p, loop = private$child_loop)
  4.       ├─promises::with_promise_domain(...)
  5.       │ └─domain$wrapSync(expr)
  6.       │   └─base::force(expr)
  7.       └─base::tryCatch(...)
  8.         └─base (local) tryCatchList(expr, classes, parentenv, handlers)
  9.           └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 10.             └─base (local) doTryCatch(return(expr), name, parentenv, handler)

I don't know if this is a chromote error only, or a webshot2 one

Or maybe v(height|width) can't be set in % - but if this is the case, then it could be checked early and error more friendly. We would also need to decide what to pass as value from knitr.

Precision on why I consider this a potential error in webshot2 - It was working with webshot

res <- webshot::webshot("https://github.com/rstudio/shiny", vwidth = 468, vheight = "100%")
str(res)
#> 'webshot' chr "webshot.png"
@cderv
Copy link
Author

cderv commented Mar 20, 2024

This is kind of related (and also reported as part of rstudio/rmarkdown#2460

fig.width = 6; dpi = 72; fig.asp = 0.618
webshot2::webshot("https://github.com/rstudio/shiny", vwidth = fig.width * dpi, vheight = fig.width * dpi * fig.asp)
#> Error in s$close(): tentative d'appliquer un objet qui n'est pas une fonction

It seems vheight does accept only integer really.

If this is requirement, there could be some checks, and better error message. Then we can decide how to process the parameters in knitr to pass them correctly for snapshoting. webshot R package supported those values, so it is appearing just now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant