wch / webshot

Take screenshots of web pages from R
http://wch.github.io/webshot/
227 stars 40 forks source link

`Error: Functions that produce HTML output found in document targeting gfm+tex_math_dollars-yaml_metadata_block output.` #118

Closed rempsyc closed 1 year ago

rempsyc commented 1 year ago

Hi, I have opened a StackOverFlow question regarding an issue with webshot and (possibly) phantomjs. Essentially, webshot does not succeed at capturing an image of an html flextable. Trying to investigate the cause of this issue, I've been trying to deal with phantomjs.

Here is a reprex of the trouble phantomjs is giving me:

webshot::is_phantomjs_installed()
#> [1] TRUE

webshot::install_phantomjs()
#> It seems that the version of `phantomjs` installed is greater than or equal to the requested version. To install 
#> the requested version or downgrade to another version, use `force = TRUE`.

webshot::install_phantomjs(force = TRUE)
#> Warning in utils::download.file(url, method = method, ...): the 'wininet'
#> method is deprecated for http:// and https:// URLs
#> phantomjs has been installed to C:\Users\rempsyc\AppData\Roaming\PhantomJS

Created on 2023-06-22 with reprex v2.0.2

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.2.2 (2022-10-31 ucrt) #> os Windows 10 x64 (build 19045) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_Canada.utf8 #> ctype English_Canada.utf8 #> tz America/New_York #> date 2023-06-22 #> pandoc 3.1.1 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> callr 3.7.3 2022-11-02 [1] CRAN (R 4.2.2) #> cli 3.6.1 2023-03-23 [1] CRAN (R 4.2.3) #> digest 0.6.31 2022-12-11 [1] CRAN (R 4.2.2) #> evaluate 0.21 2023-05-05 [1] CRAN (R 4.2.3) #> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.2.3) #> fs 1.6.2 2023-04-25 [1] CRAN (R 4.2.3) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.1.2) #> htmltools 0.5.5 2023-03-23 [1] CRAN (R 4.2.3) #> knitr 1.43 2023-05-25 [1] CRAN (R 4.2.3) #> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.2.1) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.1.3) #> processx 3.8.1 2023-04-18 [1] CRAN (R 4.2.3) #> ps 1.7.5 2023-04-18 [1] CRAN (R 4.2.3) #> purrr 1.0.1 2023-01-10 [1] CRAN (R 4.2.3) #> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.2.1) #> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.2.0) #> R.oo 1.25.0 2022-06-12 [1] CRAN (R 4.2.0) #> R.utils 2.12.2 2022-11-11 [1] CRAN (R 4.2.2) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.0.5) #> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.2.1) #> rlang 1.1.1 2023-04-28 [1] CRAN (R 4.2.3) #> rmarkdown 2.22 2023-06-01 [1] CRAN (R 4.2.3) #> rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.2.1) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.1) #> styler 1.9.1 2023-03-04 [1] CRAN (R 4.2.3) #> vctrs 0.6.2 2023-04-19 [1] CRAN (R 4.2.3) #> webshot 0.5.4 2022-09-26 [1] CRAN (R 4.2.3) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.1.2) #> xfun 0.39 2023-04-20 [1] CRAN (R 4.2.3) #> yaml 2.3.7 2023-01-23 [1] CRAN (R 4.2.2) #> #> [1] D:/Rpackages #> [2] C:/Program Files/R/R-4.2.2/library #> #> ────────────────────────────────────────────────────────────────────────────── ```

It seems that no matter how many times I use webshot::install_phantomjs(force = TRUE), I always get the message that a more recent version is installed.

Accordingly, it would be helpful if you could add the following functions:

Original flextable issue: davidgohel/flextable#532

cderv commented 1 year ago

I answered on SO. I don't think this is related to webshot. If you output your flextable in a HTML document, and then "webshot" this, I believe it will work.

knitr will use webshot or webshot2 to screenshot htmlwidgets, shiny apps or embeded URL. flextable is not a HTML widget so it does not get snapshot.

rempsyc commented 1 year ago

Thanks for your answers @cderv I really appreciate it! I'm sorry, I now realize that opening three different issues may be confusing, as now I am not sure where I should answer.

Your explanation makes sense, but it assumes that this has always been the case. But then, how would you explain that I was able to render flextables in my README files automatically for several packages without issue until after updating my packages a couple months ago? I had two different machines and in both cases it stopped working at different times, after updating packages, I presume, but I have not been able to pinpoint the source of the breakage. I did try to regress flextable but that did not solve the problem. If it is not with webshot, then maybe it is due to a change in knitr...

Here for reference is the README Rmd file for one of my packages with this problem, back to a version where it was working (4 months ago): https://github.com/rempsyc/rempsyc/blob/479852dfd0d9d1c7385abff5ab2b390e4261f514/README.Rmd#L123

(Note: nice_table is my wrapper for flextable)

And the actual README file rendering without error and displaying the plot (4 months ago): https://github.com/rempsyc/rempsyc/blob/479852dfd0d9d1c7385abff5ab2b390e4261f514/README.md

As you can see from this Rmd file, I believe webshot used to take a screenshot of the html flextable, save it as a png using the name of the chunk and appending the plot number, which could then be called below the chunk. Without having to use a plot method or flextable::save_as_image() (the workaround I currently use).

rempsyc commented 1 year ago

Solution identified in davidgohel/flextable#532: problem is with knitr >= 1.41, closing this issue.