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 fails to take screenshots of local .html under Windows #23

Closed
fdetsch opened this issue May 20, 2016 · 7 comments
Closed

webshot fails to take screenshots of local .html under Windows #23

fdetsch opened this issue May 20, 2016 · 7 comments

Comments

@fdetsch
Copy link

fdetsch commented May 20, 2016

I try to take screenshots of local .html files. The below code works fine on Ubuntu 16.04 64-bit, R version 3.0.0, but fails on the same machine using the same R version under Windows 10.

## sample widget
library(mapview)
m <- mapview(breweries91)

## save to html
htmlwidgets::saveWidget(widget = m@map, file = "~/map.html")

## save html to png 
webshot::webshot(url = "C:/Users/fdetsch/Documents/map.html", 
                 file = "C:/Users/fdetsch/Documents/map.png")

More precisely, the created .html looks just fine when opened e.g. in Firefox and the code does not throw any errors, but the resulting image is just black. On Ubuntu, by contrast, the created .png file looks just as expected. Here is my session info.

R version 3.3.0 (2016-05-03)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

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

other attached packages:
[1] mapview_1.0.29     leaflet_1.0.1.9003

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.5         raster_2.5-2        magrittr_1.5        gdalUtils_2.0.1.7   munsell_0.4.3      
 [6] colorspace_1.2-6    viridisLite_0.1.3   lattice_0.20-33     foreach_1.4.3       plyr_1.8.3         
[11] tools_3.3.0         webshot_0.3         rgdal_1.1-10        grid_3.3.0          R.oo_1.20.0        
[16] png_0.1-7           latticeExtra_0.6-28 htmltools_0.3.5     iterators_1.0.8     yaml_2.1.13        
[21] digest_0.6.9        RColorBrewer_1.1-2  htmlwidgets_0.6     R.utils_2.3.0       codetools_0.2-14   
[26] sp_1.2-3            scales_0.4.0        R.methodsS3_1.7.1   stats4_3.3.0        jsonlite_0.9.20    
[31] satellite_0.2.0 
@timelyportfolio
Copy link
Contributor

see #10, I think you just need to append file:/// to make it a valid url.

@wch
Copy link
Owner

wch commented May 20, 2016

I suppose it would be helpful to include an example of the correct path to use on Windows. Or maybe it would be better to make webshot automatically fix paths on Windows.

@fdetsch
Copy link
Author

fdetsch commented May 23, 2016

file:/// works, thanks a lot! Winston, wouldn't it be possible to retrieve the required OS information via Sys.info()[["sysname"]] and add file:/// if necessary?

@wch
Copy link
Owner

wch commented May 23, 2016

@fdetsch We would also have to have a good way of detecting whether the path is to a local file, or a remote one. I think searching for the regex ^\w+?:// should work.

@yihui
Copy link
Collaborator

yihui commented May 26, 2016

I'd recommend you to avoid absolute paths -- setwd() to the directory of the html file, take a screenshot using the base filename, and restore the working directory. Then you would not need to worry about issues like file:/// or forward slashes / backslashes.

@wch wch closed this as completed in a69ab5f Jun 22, 2016
@alipprc
Copy link

alipprc commented May 3, 2018

I have the opposite problem !!!
can somebody help me here :
https://stackoverflow.com/questions/50154257/webshot-fails-to-take-screenshots-of-local-html-under-linux

@gauravdhiman
Copy link

@timelyportfolio thanks for your pointer. I was struggling with it for last 2 hours ... you saved me many more hours !!

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

6 participants