rstudio / webshot2

Take screenshots of web pages from R

Home Page:https://rstudio.github.io/webshot2/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug Report: attempt to apply non-function

JiaxiangBU opened this issue · comments

Here is the reproducible minimal example.

> codelf <- "https://unbug.github.io/codelf/#ggplot"
> library(webshot2)
> webshot(codelf)
Error in s$close() : attempt to apply non-function

Here is the session info.

"si"
#> [1] "si"

Created on 2019-08-08 by the reprex package (v0.2.1)

Session info
devtools::session_info()
#> - Session info ----------------------------------------------------------
#>  setting  value                                              
#>  version  R version 3.5.2 (2018-12-20)                       
#>  os       Windows 7 x64 SP 1                                 
#>  system   x86_64, mingw32                                    
#>  ui       RTerm                                              
#>  language (EN)                                               
#>  collate  Chinese (Simplified)_People's Republic of China.936
#>  ctype    Chinese (Simplified)_People's Republic of China.936
#>  tz       Asia/Taipei                                        
#>  date     2019-08-08                                         
#> 
#> - Packages --------------------------------------------------------------
#>  package     * version date       lib source        
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 3.5.3)
#>  backports     1.1.4   2019-04-10 [1] CRAN (R 3.5.3)
#>  callr         3.2.0   2019-03-15 [1] CRAN (R 3.5.3)
#>  cli           1.1.0   2019-03-19 [1] CRAN (R 3.5.3)
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 3.5.2)
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 3.5.2)
#>  devtools      2.0.2   2019-04-08 [1] CRAN (R 3.5.3)
#>  digest        0.6.19  2019-05-20 [1] CRAN (R 3.5.3)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 3.5.3)
#>  fs            1.3.1   2019-05-06 [1] CRAN (R 3.5.3)
#>  glue          1.3.1   2019-03-12 [1] CRAN (R 3.5.3)
#>  highr         0.8     2019-03-20 [1] CRAN (R 3.5.3)
#>  htmltools     0.3.6   2017-04-28 [1] CRAN (R 3.5.2)
#>  knitr         1.23    2019-05-18 [1] CRAN (R 3.5.3)
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 3.5.2)
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 3.5.2)
#>  pkgbuild      1.0.3   2019-03-20 [1] CRAN (R 3.5.3)
#>  pkgload       1.0.2   2018-10-29 [1] CRAN (R 3.5.2)
#>  prettyunits   1.0.2   2015-07-13 [1] CRAN (R 3.5.2)
#>  processx      3.4.1   2019-07-18 [1] CRAN (R 3.5.3)
#>  ps            1.3.0   2018-12-21 [1] CRAN (R 3.5.2)
#>  R6            2.4.0   2019-02-14 [1] CRAN (R 3.5.3)
#>  Rcpp          1.0.2   2019-07-25 [1] CRAN (R 3.5.3)
#>  remotes       2.1.0   2019-06-24 [1] CRAN (R 3.5.3)
#>  rlang         0.4.0   2019-06-25 [1] CRAN (R 3.5.3)
#>  rmarkdown     1.13    2019-05-22 [1] CRAN (R 3.5.3)
#>  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 3.5.2)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.5.3)
#>  stringi       1.4.3   2019-03-12 [1] CRAN (R 3.5.3)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 3.5.3)
#>  testthat      2.1.1   2019-04-23 [1] CRAN (R 3.5.3)
#>  usethis       1.5.0   2019-04-07 [1] CRAN (R 3.5.3)
#>  withr         2.1.2   2018-03-15 [1] CRAN (R 3.5.2)
#>  xfun          0.8     2019-06-25 [1] CRAN (R 3.5.3)
#>  yaml          2.2.0   2018-07-25 [1] CRAN (R 3.5.2)
#> 
#> [1] C:/Program Files/R/R-3.5.2/library

I don't see webshot2 in your list of loaded packages. Did you successfully install it? Also, since you are on Windows, it is important to restart R before installing it, to make sure that the upstream dependencies get upgraded properly.

Hi, @wch I make a new reproducible minimal example. The package webshot2 is listed in the folded session information. The error message is held the same.

#>  webshot2      0.0.0.9000 2019-08-08 [1] Github (rstudio/webshot2@03a0fbd)
webshot2::webshot("https://unbug.github.io/codelf/#ggplot")
#> Error in s$close(): 不适用于非函数

Created on 2019-08-09 by the reprex package (v0.2.1)

Session info
devtools::session_info()
#> - Session info ----------------------------------------------------------
#>  setting  value                                              
#>  version  R version 3.5.2 (2018-12-20)                       
#>  os       Windows 7 x64 SP 1                                 
#>  system   x86_64, mingw32                                    
#>  ui       RTerm                                              
#>  language (EN)                                               
#>  collate  Chinese (Simplified)_People's Republic of China.936
#>  ctype    Chinese (Simplified)_People's Republic of China.936
#>  tz       Asia/Taipei                                        
#>  date     2019-08-09                                         
#> 
#> - Packages --------------------------------------------------------------
#>  package     * version    date       lib source                           
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.5.3)                   
#>  backports     1.1.4      2019-04-10 [1] CRAN (R 3.5.3)                   
#>  callr         3.2.0      2019-03-15 [1] CRAN (R 3.5.3)                   
#>  chromote      0.0.0.9001 2019-08-08 [1] Github (rstudio/chromote@7541986)
#>  cli           1.1.0      2019-03-19 [1] CRAN (R 3.5.3)                   
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.5.2)                   
#>  curl          3.3        2019-01-10 [1] CRAN (R 3.5.3)                   
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.5.2)                   
#>  devtools      2.0.2      2019-04-08 [1] CRAN (R 3.5.3)                   
#>  digest        0.6.19     2019-05-20 [1] CRAN (R 3.5.3)                   
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 3.5.3)                   
#>  fastmap       1.0.0      2019-07-28 [1] CRAN (R 3.5.3)                   
#>  fs            1.3.1      2019-05-06 [1] CRAN (R 3.5.3)                   
#>  glue          1.3.1      2019-03-12 [1] CRAN (R 3.5.3)                   
#>  highr         0.8        2019-03-20 [1] CRAN (R 3.5.3)                   
#>  htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.5.2)                   
#>  jsonlite      1.6        2018-12-07 [1] CRAN (R 3.5.2)                   
#>  knitr         1.23       2019-05-18 [1] CRAN (R 3.5.3)                   
#>  later         0.8.0.9003 2019-08-08 [1] Github (r-lib/later@ae297fa)     
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.5.2)                   
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.5.2)                   
#>  pkgbuild      1.0.3      2019-03-20 [1] CRAN (R 3.5.3)                   
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.5.2)                   
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.5.2)                   
#>  processx      3.4.1      2019-07-18 [1] CRAN (R 3.5.3)                   
#>  promises      1.0.1.9002 2019-08-08 [1] Github (rstudio/promises@9ebad6d)
#>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.5.2)                   
#>  R6            2.4.0      2019-02-14 [1] CRAN (R 3.5.3)                   
#>  Rcpp          1.0.2      2019-07-25 [1] CRAN (R 3.5.3)                   
#>  remotes       2.1.0      2019-06-24 [1] CRAN (R 3.5.3)                   
#>  rlang         0.4.0      2019-06-25 [1] CRAN (R 3.5.3)                   
#>  rmarkdown     1.13       2019-05-22 [1] CRAN (R 3.5.3)                   
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.5.2)                   
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.5.3)                   
#>  stringi       1.4.3      2019-03-12 [1] CRAN (R 3.5.3)                   
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.5.3)                   
#>  testthat      2.1.1      2019-04-23 [1] CRAN (R 3.5.3)                   
#>  usethis       1.5.0      2019-04-07 [1] CRAN (R 3.5.3)                   
#>  webshot2      0.0.0.9000 2019-08-08 [1] Github (rstudio/webshot2@03a0fbd)
#>  websocket     1.0.0      2019-06-18 [1] CRAN (R 3.5.3)                   
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.5.2)                   
#>  xfun          0.8        2019-06-25 [1] CRAN (R 3.5.3)                   
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.5.2)                   
#> 
#> [1] C:/Program Files/R/R-3.5.2/library

One possibility is that there was a problem upgrading some of those packages. In Windows, if you upgrade a package with compiled code that is loaded (in any R session), all of the files in the package will get upgraded except the DLL, which can cause strange problems. R does produce a warning in this situation, but it is in the middle of a lot of other output and easy to overlook. Please make sure that when you upgrade these packages, you are doing it in a new R session with no packages loaded, and make sure there are no other R sessions running.

I suggest restarting R (and quitting all other R sessions), and installing later, promises, chromote, and webshot2 packages from GitHub. When you install them use devtools::install_github(force = TRUE).

If that still doesn't help, try running:

library(chromote)
s <- ChromoteSesssion$new()
s$Page$navigate("https://www.r-project.org")
s$view()

If that works (and you see the web page), then at least that part works. If it does not work, then please provide any error messages from it.

Same problem here, just now started a new session, installed those packages from github with force=TRUE, then ran

library(chromote)
s <- ChromoteSesssion$new()

and got the error Error: object 'ChromoteSesssion' not found.

R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] chromote_0.0.0.9002

loaded via a namespace (and not attached):
[1] Rcpp_1.0.3 rstudioapi_0.10 magrittr_1.5 usethis_1.5.1
[5] devtools_2.1.0 pkgload_1.0.2 R6_2.4.1 rlang_0.4.5
[9] fastmap_1.0.1 fansi_0.4.0 tools_3.6.0 websocket_1.2.0
[13] pkgbuild_1.0.4 packrat_0.5.0 sessioninfo_1.1.1 cli_2.0.0
[17] withr_2.1.2 remotes_2.1.0 rprojroot_1.3-2 assertthat_0.2.1
[21] digest_0.6.25 crayon_1.3.4 processx_3.4.1 callr_3.4.0
[25] later_1.1.0.9000 fs_1.4.1 promises_1.1.1.9000 ps_1.3.0
[29] curl_4.3 testthat_2.2.1 memoise_1.1.0 glue_1.4.0
[33] compiler_3.6.0 backports_1.1.5 desc_1.2.0 prettyunits_1.0.2
[37] jsonlite_1.6

I have exactly the same problem. Webshot was working ok during the session and then started giving out this:
Error in s$close() : attempt to apply non-function error.

Testing:

> library(chromote)
> s <- ChromoteSesssion$new()
Error: object 'ChromoteSesssion' not found

I am getting the same error on Linux. On Windows its working fine.

@wch You've got a typo in your previous answer. It should be ChromoteSession with double s, not triple.

I get this error from a plumber service. There I am getting:
<simpleError in s$close(): Versuch eine Nicht-Funktion anzuwenden>

Via the R terminal as my user this code works:
s <- chromote::ChromoteSession$new()

As root I am getting this via the R terminal:
s <- chromote::ChromoteSession$new()

`Fehler in launch_chrome(path, args) :
  Failed to start chrome. Error: mkdir: cannot create directory '/run/user/0': Permission denied
[1227/142846.158913:ERROR:zygote_host_impl_linux.cc(100)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.