kableExtra icon indicating copy to clipboard operation
kableExtra copied to clipboard

`save_kable` and `as_image` generating `PHANTOM ERROR: TypeError: undefined is not a constructor`

Open daaronr opened this issue 3 years ago • 1 comments

Describe the bug When I use save_kable and as_image it yields PHANTOM ERROR: TypeError: undefined is not a constructor

I am struggling to get webshot to work in general although webshot2 works in isolation.

I get into this in the SO post here

If there were a way to have kable_Extra swap webshot2 in for webshot this might fix it. I think webshot might not be compatible with some systems?

To Reproduce Think about using reprex to generate an example in R.

library(dplyr) 
library(kableExtra)

install.packages("magick")
install.packages("webshot")
webshot::install_phantomjs(force=TRUE)

library(magick)
library(webshot)

mtcars %>% as_tibble() %>%
  janitor::tabyl(cyl) %>%
  kable(caption="don't forget a caption") %>%
  kable_styling() %>% 
save_kable("testmtcarsimage.png")

I'm `fs` modules
PHANTOM ERROR: TypeError: undefined is not a constructor (evaluating 'require('fs').pathJoin(phantom.casperPath, 'modules', 'clientutils.js')')
TRACE:
 -> phantomjs://platform/casper.js: 1309 (in function injectClientUtils)
 -> phantomjs://platform/casper.js: 713 (in function evaluate)
 -> phantomjs://platform/casper.js: 1008 (in function getCurrentUrl)
 -> phantomjs://platform/casper.js: 1590 (in function runStep)
 -> phantomjs://platform/casper.js: 406 (in function checkStep)
Error in webshot::webshot(file_temp_html, file, ...) : 
  webshot.js returned failure value: 1
> 
> traceback()
5: stop("webshot.js returned failure value: ", res)
4: webshot::webshot(file_temp_html, file, ...)
3: save_kable_html(x, file, bs_theme, self_contained, extra_dependencies, 
       density, ...)
2: save_kable(., "testmtcarsimage.png")
1: mtcars %>% as_tibble() %>% janitor::tabyl(cyl) %>% kable(caption = "don't forget a caption") %>% 
       kable_styling() %>% save_kable("testmtcarsimage.png")
> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

Random number generation:
 RNG:     Mersenne-Twister 
 Normal:  Inversion 
 Sample:  Rounding 
 
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

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

other attached packages:
[1] dplyr_1.0.7         kableExtra_1.3.4    webshot2_0.0.0.9000
[4] webshot_0.5.2      

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.1    xfun_0.26           janitor_2.1.0      
 [4] remotes_2.4.1       purrr_0.3.4         snakecase_0.11.0   
 [7] colorspace_2.0-2    vctrs_0.3.8         generics_0.1.0     
[10] htmltools_0.5.2     viridisLite_0.4.0   utf8_1.2.2         
[13] rlang_0.4.11        jquerylib_0.1.4     later_1.3.0        
[16] pillar_1.6.3        glue_1.4.2          lifecycle_1.0.1    
[19] stringr_1.4.0       munsell_0.5.0       rvest_1.0.1        
[22] chromote_0.0.0.9003 websocket_1.4.1     evaluate_0.14      
[25] knitr_1.36          callr_3.7.0         fastmap_1.1.0      
[28] ps_1.6.0            parallel_4.1.1      curl_4.3.2         
[31] fansi_0.5.0         highr_0.9           Rcpp_1.0.7         
[34] renv_0.13.2         promises_1.2.0.1    scales_1.1.1       
[37] jsonlite_1.7.2      systemfonts_1.0.2   digest_0.6.28      
[40] stringi_1.7.4       processx_3.5.2      grid_4.1.1         
[43] tools_4.1.1         magrittr_2.0.1      tibble_3.1.5       
[46] tidyr_1.1.4         crayon_1.4.1        pkgconfig_2.0.3    
[49] ellipsis_0.3.2      xml2_1.3.2          lubridate_1.7.10   
[52] rmarkdown_2.11      svglite_2.0.0       httr_1.4.2         
[55] rstudioapi_0.13     R6_2.5.1            compiler_4.1.1 

daaronr avatar Oct 01 '21 20:10 daaronr

I just realized this is a partial duplicate of https://github.com/haozhu233/kableExtra/issues/618, although I go into the nature of the bug I'm having a bit more

daaronr avatar Oct 01 '21 22:10 daaronr

reinstall and installing the kableExtra library will resolve the issue tableX

Nesh45 avatar Jun 18 '23 11:06 Nesh45

I had the same issue and resolved it by reinstalling the package my code data[anomalies,]%>% kbl(caption ="Anomalies",booktabs =T,align ="l")%>% kable_classic(lightable_options ="striped",html_font ="Arial")%>% save_kable(file = 'tableX.png',bs_theme = "flatly")

Nesh45 avatar Jun 18 '23 11:06 Nesh45

I believe this is now fixed in the dev version on GitHub: https://github.com/haozhu233/kableExtra/pull/768

vincentarelbundock avatar Dec 04 '23 22:12 vincentarelbundock