2016-06-22 6 views
1

Ich versuche, ein Screenshot Bild von rPivotTable in Shiny zu bekommen. Ich speichere das rpivotable mit saveWidget() von htmlwidgets. Ich möchte dann webshot() verwenden, um das HTML in JPEG-Bild zu konvertieren. Das von saveWidget generierte HTML wird in Firefox korrekt angezeigt, aber das von webshot generierte Bild ist leer. Ich habe das von webshot generierte Bild angehängt. myPivot.jpegR Webshot jpeg Bild ist leer

Unten ist ein Beispielcode I mit

arbeiten am
library(rpivotTable) 
library(htmlwidgets) 
library(webshot) 
mypivot <- rpivotTable(mtcars, rows = "cyl", cols = "mpg") 

saveWidget(mypivot, "myPivot.html", selfcontained = FALSE) 

webshot(url = "myPivot.html", file = "myPivot.jpeg") 

Ich habe dann versucht, eine der Lösungen von How to save Leaflet in RStudio map as png or jpg file? ich immer noch nur leeres Bild als die Ausgabe immer bin zu verwenden. Unten ist das Bild erzeugt (Sein vollständig leeres Weiß) RPlot.png

Unten ist der Code, den ich verwende.

library(leaflet) 
library(htmlwidgets) 
library(webshot) 

## create map 
m <- leaflet() %>% addTiles() 

## save html to png 
saveWidget(m, "temp.html", selfcontained = FALSE) 
webshot("temp.html", file = "Rplot.png", 
     cliprect = "viewport") 

Unten finden Sie Informationen zu meiner R Session. Ich benutze RStudio.

R> sessionInfo() 
R version 3.2.2 (2015-08-14) 
Platform: x86_64-w64-mingw32/x64 (64-bit) 
Running under: Windows 7 x64 (build 7601) Service Pack 1 
locale: 
[2] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 
[4] LC_NUMERIC=C       LC_TIME=English_United States.1252  
attached base packages: 
[2] stats  graphics grDevices utils  datasets methods base  
other attached packages: 
[2] rpivotTable_0.1.5.20 htmlwidgets_0.6  mapview_1.1.0  leaflet_1.0.1  webshot_0.3   htmltools_0.3.5  
loaded via a namespace (and not attached): 
[2] Rcpp_0.12.5   RColorBrewer_1.1-2 plyr_1.8.4   R.methodsS3_1.7.1 R.utils_2.3.0  viridis_0.3.4  base64enc_0.1-3  
[8] iterators_1.0.8  tools_3.2.2   gdalUtils_2.0.1.7 digest_0.6.9  viridisLite_0.1.3 satellite_0.2.0  lattice_0.20-33  
[15] jsonlite_0.9.22  gtable_0.2.0  png_0.1-7   foreach_1.4.3  shiny_0.13.2  DBI_0.4-1   yaml_2.1.13   
[22] rgdal_1.1-10  parallel_3.2.2  gridExtra_2.2.1  dplyr_0.4.3   httr_1.1.0   raster_2.5-8  stats4_3.2.2  
[29] grid_3.2.2   R6_2.1.2   plotly_3.6.0  sp_1.2-3   latticeExtra_0.6-28 tidyr_0.4.1   ggplot2_2.1.0  
[36] magrittr_1.5  scales_0.4.0  codetools_0.2-14 assertthat_0.1  mime_0.4   xtable_1.8-2  colorspace_1.2-6 
[43] httpuv_1.3.3  munsell_0.4.3  R.oo_1.20.0 

Antwort

0

Verspätete Antwort!

Die folgenden Werke für mich:

library(rpivotTable) 
library(htmlwidgets) 

savedPivot <- "savedPivot.html" 
rpivotTable(iris) 
saveWidget(rpivotTable(iris),file.path(normalizePath(dirname(savedPivot)),basename(savedPivot))) 

(basierend auf @malcook Antwort auf SO here)