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

Webshot cuts off images with plotly widgets #73

Open
kmalone7 opened this issue Jan 10, 2019 · 2 comments
Open

Webshot cuts off images with plotly widgets #73

kmalone7 opened this issue Jan 10, 2019 · 2 comments

Comments

@kmalone7
Copy link

kmalone7 commented Jan 10, 2019

I am trying to include static images of plotly widgets in my rmarkdown reports. I like the interactively of plotly so I save the widgets locally, but they take up too much space when knitting. I have been able to do this by two ways. Either in the code chunk using the option screenshot.force=TRUE (uses webshot) or saving the widget locally with saveWidget() and then using the webshot() function. The issue is that the image is cut off at the lower portion of the y-axis, which is bothersome. I would expect the whole image to be saved with webshot. I have tried adjusting the features of vwidth, vheight, and cliprect with no luck. Though this seems to work properly with other widgets like leaflet.

To reproduce make any simple plot_ly plot, save the widget with saveWidget, then save a png with webshot.

Example script:
require(webshot)
require(plotly)
require(htmlwidgets)
data("iris")
simple_plot=plot_ly(x=iris$Petal.Width,y=iris$Petal.Length,type="scatter",mode="markers")
saveWidget(widget = simple_plot,file = "simple_plot.html")
webshot(url = "simple_plot.html",file = "webshot_iris.png")

To see this I am attaching image from webshot (second image) and a manual screenshot from savewidget (first image). Notice that the webshot version is cut off with the lower numbers on the y-axis
simple_plot_manualscreenshot

webshot_iris

Session info:

R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

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

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

other attached packages:
[1] htmlwidgets_1.2 bindrcpp_0.2.2 plotly_4.8.0 ggplot2_3.0.0 webshot_0.5.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.18 later_0.7.3 pillar_1.3.0 compiler_3.5.2 plyr_1.8.4 bindr_0.1.1
[7] tools_3.5.2 digest_0.6.15 jsonlite_1.5 tibble_1.4.2 gtable_0.2.0 viridisLite_0.3.0
[13] pkgconfig_2.0.1 rlang_0.2.1 shiny_1.1.0 rstudioapi_0.7 crosstalk_1.0.0 yaml_2.2.0
[19] withr_2.1.2 dplyr_0.7.6 httr_1.3.1 grid_3.5.2 tidyselect_0.2.4 glue_1.3.0
[25] data.table_1.11.4 R6_2.2.2 processx_3.1.0 callr_2.0.4 purrr_0.2.5 tidyr_0.8.1
[31] magrittr_1.5 promises_1.0.1 scales_0.5.0 htmltools_0.3.6 assertthat_0.2.0 xtable_1.8-2
[37] mime_0.5 colorspace_1.3-2 httpuv_1.4.5 lazyeval_0.2.1 munsell_0.5.0 crayon_1.3.4

@ldfreight
Copy link

ldfreight commented Mar 13, 2019

I have same issue! (with same version of packages plotly_4.8.0 webshot_0.5.1)
It was working previously for me.
However I decided to upgrade all my packages and now I face same issue.
Given I upgraded all packages at once I am unable to tell if the issue started with a new version of webshot or of plotly

Similar reproducible example as above

library(plotly)
library(webshot)

# install_phantomjs() # this has installed https://github.com/wch/webshot/releases/download/v0.3.1/phantomjs-2.1.1-windows.zip

data <- data.frame(x=1:100, random_y=rnorm(100, mean = 0))
widget <- plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines')

tempfile = tempfile(pattern = "widgetToPng_")
filePathHTML = paste0(tempfile,".html")
filePathPNG  = paste0(tempfile,".png")

htmlwidgets::saveWidget(widget = widget, file = filePathHTML) # at this stage the html is complete

webshot(url = filePathHTML, file = filePathPNG)

HTML:
image

PNG
Untitled

R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] C

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

other attached packages:
[1] plotly_4.8.0 webshot_0.5.1 bindrcpp_0.2.2 LDFreightIndicators_18.8.1 LDBacktest_18.10.2 LDFreight_19.3.41 caret_6.0-81 ggplot2_3.1.0
[9] lattice_0.20-38 leaflet_2.0.2 dygraphs_1.1.1.6 curl_3.3 quantmod_0.4-13 TTR_0.23-4 LDDataAccessLayeR_19.3.3 usethis_1.4.0
[17] devtools_2.0.1 tibble_2.0.1 xts_0.11-2 zoo_1.8-4

loaded via a namespace (and not attached):
[1] nlme_3.1-137 fs_1.2.6 lubridate_1.7.4 bit64_0.9-7 httr_1.4.0 rprojroot_1.3-2 tools_3.4.2 backports_1.1.3 R6_2.3.0 rpart_4.1-13 DBI_1.0.0
[12] lazyeval_0.2.1 colorspace_1.4-0 nnet_7.3-12 withr_2.1.2 tidyselect_0.2.5 prettyunits_1.0.2 processx_3.2.1 bit_1.1-14 compiler_3.4.2 cli_1.0.1 desc_1.2.0
[23] scales_1.0.0 callr_3.1.1 odbc_1.1.6 stringr_1.3.1 digest_0.6.18 rmarkdown_1.11 pkgconfig_2.0.2 htmltools_0.3.6 sessioninfo_1.1.1 dbplyr_1.3.0 htmlwidgets_1.3
[34] rlang_0.3.1 rstudioapi_0.9.0 shiny_1.2.0 bindr_0.1.1 generics_0.0.2 jsonlite_1.6 crosstalk_1.0.0 dplyr_0.7.8 ModelMetrics_1.2.2 magrittr_1.5 Matrix_1.2-15
[45] Rcpp_1.0.0 munsell_0.5.0 RODBC_1.3-15 stringi_1.2.4 yaml_2.2.0 MASS_7.3-51.1 pkgbuild_1.0.2 plyr_1.8.4 recipes_0.1.4 blob_1.1.1 grid_3.4.2
[56] promises_1.0.1 crayon_1.3.4 splines_3.4.2 hms_0.4.2 magick_2.0 knitr_1.21 ps_1.3.0 pillar_1.3.1 reshape2_1.4.3 codetools_0.2-16 stats4_3.4.2
[67] pkgload_1.0.2 glue_1.3.0 evaluate_0.12 data.table_1.12.0 remotes_2.0.2 httpuv_1.4.5.1 foreach_1.4.4 testthat_2.0.1 gtable_0.2.0 purrr_0.3.0 tidyr_0.8.2
[78] assertthat_0.2.0 xfun_0.4 formattable_0.2.0.1 gower_0.1.2 mime_0.6 prodlim_2018.04.18 xtable_1.8-3 later_0.7.5 viridisLite_0.3.0 class_7.3-15 survival_2.43-3
[89] timeDate_3043.102 iterators_1.0.10 memoise_1.1.0 lava_1.6.4 ipred_0.9-8

@cpsievert
Copy link

It appears https://github.com/rstudio/webshot2 doesn't suffer from this issue...consider using webshot2::webshot() instead.

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

3 participants