yonicd / carbonate

carbon.js for R
https://yonicd.github.io/carbonate/
Other
212 stars 5 forks source link

RSelenium/carbonate Windows #15

Closed maelle closed 6 years ago

maelle commented 6 years ago

Describe the bug

I can't take a screenshot of the object.

To Reproduce

# carbonate
reprex::reprex(plot(1:10),
               outfile = "demo_carbonate",
               venue = "r")
#> Preparing reprex as .R file:
#>   * demo_carbonate_reprex.R
#> Rendering reprex...
#> Writing reprex markdown:
#>   * demo_carbonate_reprex.md
#> Writing reprex as commented R script:
#>   * demo_carbonate_reprex_rendered.R
#> Rendered reprex is on the clipboard.

x <- carbonate::carbon$new(readLines('demo_carbonate_reprex_rendered.R'))
x$carbonate(file = 'myfile.png')
#> starting chrome session...
#> checking chromedriver versions:
#> BEGIN: PREDOWNLOAD
#> BEGIN: DOWNLOAD
#> BEGIN: POSTDOWNLOAD
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> 
#> 
#> Selenium message:no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/main/div[2]/div/div[1]/div[5]/div"}
#>   (Session info: chrome=69.0.3497.100)
#>   (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Windows NT 10.0.17134 x86_64)
#> Error: attempt to fetch image from carbon servers failed, 
#>          please check network connectivity and try again

Created on 2018-09-29 by the reprex package (v0.2.1)

Session info ``` r devtools::session_info() #> Session info ------------------------------------------------------------- #> setting value #> version R version 3.5.0 (2018-04-23) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.1252 #> tz Europe/Paris #> date 2018-09-29 #> Packages ----------------------------------------------------------------- #> package * version date source #> assertthat 0.2.0 2017-04-11 CRAN (R 3.5.0) #> backports 1.1.2 2017-12-13 CRAN (R 3.5.0) #> base * 3.5.0 2018-04-23 local #> base64enc 0.1-3 2015-07-28 CRAN (R 3.5.0) #> binman 0.1.1 2018-07-18 CRAN (R 3.5.1) #> bitops 1.0-6 2013-08-17 CRAN (R 3.5.0) #> callr 3.0.0 2018-08-24 CRAN (R 3.5.1) #> carbonate 0.0.1 2018-09-29 Github (yonicd/carbonate@0c8b769) #> caTools 1.17.1.1 2018-07-20 CRAN (R 3.5.1) #> clipr 0.4.1 2018-06-23 CRAN (R 3.5.0) #> compiler 3.5.0 2018-04-23 local #> crayon 1.3.4 2017-09-16 CRAN (R 3.5.0) #> curl 3.2 2018-03-28 CRAN (R 3.5.0) #> datasets * 3.5.0 2018-04-23 local #> debugme 1.1.0 2017-10-22 CRAN (R 3.5.0) #> devtools 1.13.6 2018-06-27 CRAN (R 3.5.1) #> digest 0.6.17 2018-09-12 CRAN (R 3.5.1) #> evaluate 0.11 2018-07-17 CRAN (R 3.5.1) #> fs 1.2.6 2018-08-23 CRAN (R 3.5.1) #> graphics * 3.5.0 2018-04-23 local #> grDevices * 3.5.0 2018-04-23 local #> htmltools 0.3.6 2017-04-28 CRAN (R 3.5.1) #> httr 1.3.1 2017-08-20 CRAN (R 3.5.0) #> jsonlite 1.5 2017-06-01 CRAN (R 3.5.0) #> knitr 1.20 2018-02-20 CRAN (R 3.5.0) #> magick 1.9 2018-05-11 CRAN (R 3.5.0) #> magrittr 1.5 2014-11-22 CRAN (R 3.5.0) #> memoise 1.1.0 2017-04-21 CRAN (R 3.5.0) #> methods * 3.5.0 2018-04-23 local #> openssl 1.0.2 2018-07-30 CRAN (R 3.5.0) #> processx 3.2.0 2018-08-16 CRAN (R 3.5.1) #> ps 1.1.0 2018-08-10 CRAN (R 3.5.1) #> R6 2.2.2 2017-06-17 CRAN (R 3.5.0) #> rappdirs 0.3.1 2016-03-28 CRAN (R 3.5.0) #> Rcpp 0.12.18 2018-07-23 CRAN (R 3.5.0) #> reprex 0.2.1 2018-09-16 CRAN (R 3.5.1) #> rlang 0.2.2 2018-08-16 CRAN (R 3.5.1) #> rmarkdown 1.10 2018-06-11 CRAN (R 3.5.0) #> rprojroot 1.3-2 2018-01-03 CRAN (R 3.4.3) #> RSelenium 1.7.4 2018-09-18 CRAN (R 3.5.1) #> rtweet 0.6.8 2018-09-28 CRAN (R 3.5.0) #> semver 0.2.0 2017-01-06 CRAN (R 3.5.1) #> stats * 3.5.0 2018-04-23 local #> stringi 1.2.4 2018-07-23 local #> stringr 1.3.1 2018-05-10 CRAN (R 3.5.0) #> subprocess 0.8.3 2018-08-13 CRAN (R 3.5.1) #> tools 3.5.0 2018-04-23 local #> utils * 3.5.0 2018-04-23 local #> wdman 0.2.4 2018-07-21 CRAN (R 3.5.1) #> whisker 0.3-2 2013-04-28 CRAN (R 3.4.0) #> withr 2.1.2 2018-03-15 CRAN (R 3.4.4) #> XML 3.98-1.16 2018-08-19 CRAN (R 3.5.1) #> xml2 1.2.0 2018-01-24 CRAN (R 3.5.0) #> yaml 2.2.0 2018-07-25 CRAN (R 3.5.1) ```
maelle commented 6 years ago

it looks like an RSelenium bug/wrong setup though. Happy to hear any thought and to take my bug report/own mistake elsewhere.

yonicd commented 6 years ago

I don't have a windows OS on hand. the only place RSelenium is being 'setup' is here and here.

In the latter the disable-gpu switch is meant to be for windows.

I have a feeling that @juyeongkim would have a quicker answer on that.

maelle commented 6 years ago

@juyeongkim I can provide more info and we can move this convo to the RSelenium repo if you want.

yonicd commented 6 years ago

@maelle i just ran it on my OS it gets the same thing as you. the carbon page must have changed. I'll reset the xpaths (not the first time that page has been changed). Thanks for catching this.

maelle commented 6 years ago

Ah very cool! Happy to be of help, looking forward to getting PNGs! 🎉

yonicd commented 6 years ago

https://github.com/yonicd/carbonate/commit/f64f1e940940b2d937f44bb254c4985c17c17d78

yonicd commented 6 years ago

The ci passed. So once you verify for windows I’ll pr this branch.

maelle commented 6 years ago

Installing now!

maelle commented 6 years ago

Yay it worked! Thanks!

Btw have you thought of wrapping the source code of carbon.js itself to create the pic locally? Is it even possible?

maelle commented 6 years ago

Actually an image was created, but not saved to disk, is this normal?

maelle commented 6 years ago

i.e. I then had to run magick::image_write(x$carbons, "myfile.png") to save the image.

maelle commented 6 years ago

(and sorry for all the questions... such a neat package!!)

yonicd commented 6 years ago

great questions :).

using the carbon.js script was my first instinct too to create an htmlwidget, but they dont give access to the raw script (only throught the website).

the default to save to disk is tempdir(). to set the output dir you need to do

x$chrome_pref$download.default_directory <- MYPATH

example from the readme

maelle commented 6 years ago

using the carbon.js script was my first instinct too to create an htmlwidget, but they dont give access to the raw script (only throught the website).

Interesting! Now I wonder about the possibility to make a similar, less pretty/customizable tool via magick::image_annotate (that supports different fonts) 🤔

Oops sorry for not reading the docs enough! Would it make sense for carbonate to expose the dir argument? i.e.

x$carbonate(file = 'myfile.png', dir = getwd())

with dir being x$chrome_pref$download.default_directory by default?

yonicd commented 6 years ago

That would be nice, but chrome pref controls The download dir. what may work is to have an exposed method that wraps around that nested element to simplify the api.

The first comment about using magick instead sounds like a big undertaking, carbonjs is pretty complex to mimic (at least for me ;))

yonicd commented 6 years ago

Reread your dir suggestion. Could work, but I’m not next to a computer for most of the day. Your welcome to fork and play around with it. Improving the api is always welcome.

maelle commented 6 years ago

Reg the non-carbonate solution, do you know of https://github.com/ropenscilabs/codefinch? It uses rendering to PDF and then rendering of the PDF to an image (via pdftools). Not as pretty, but then one doesn't need a website. :-)

Will make a small try for the dir.

maelle commented 6 years ago

sorry I won't have time to do the dir edit myself.

yonicd commented 6 years ago

No worries, I’ll take a look tonight.

yonicd commented 6 years ago

I think user experience would increase once headless chrome download to location bug is fixed.

yonicd commented 6 years ago

see example to set download dir directly from carbonate call above this

https://github.com/yonicd/carbonate/commit/184535b8c832889e6b36b199c781c598a0d99483

maelle commented 6 years ago

Awesome, thank you!

yonicd commented 6 years ago

removed the output_dir. it was causing trouble with the RSelenium driver since the directory is being set at the self$start. The way it was (while more cumbersome) is more robust and less prone to errors.

https://github.com/yonicd/carbonate/commit/1c09d8e1d826f6744ac3f507bc712a0367a7b861