我正在试着在闪亮中获取rPivotTable的截图。我使用htmlwidgets中的saveWidget()保存rpivottable。然后,我想使用webshot()将html转换为jpeg图像。从saveWidget生成的html在Firefox中显示正确,但webshot生成的图像为空。我已经附上了webshot生成的图像。

下面是我正在使用的示例代码
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")然后我尝试使用How to save Leaflet in RStudio map as png or jpg file?的一个解决方案,我仍然只得到空白图像作为输出。下面是生成的图像(完全空白的白色)

下面是我使用的代码。
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")下面是关于我的R会话的信息。我正在使用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发布于 2020-05-18 23:50:00
你应该考虑在https://github.com/rstudio/webshot2上尝试webshot2,而不是使用webshot。我准备了一篇博文,其中包含了关于webshot2的各种细节。您可以从此处查看详细信息。此外,关于webshot与webshot2的问题,请参阅我的详细答案。
我已经用webshot2复制了您的方案。考虑到文件扩展名在webshot2中必须是'png‘或'pdf’,因此也要对其进行修改。
代码
library(rpivotTable)
library(htmlwidgets)
library(webshot2)
mypivot <- rpivotTable(mtcars, rows = "cyl", cols = "mpg")
saveWidget(mypivot, "myPivot.html", selfcontained = FALSE)
webshot(url = "myPivot.html", file = "myPivot.png")输出文件

发布于 2017-10-15 18:04:48
迟来的回应!
下面的方法对我很有效:
library(rpivotTable)
library(htmlwidgets)
savedPivot <- "savedPivot.html"
rpivotTable(iris)
saveWidget(rpivotTable(iris),file.path(normalizePath(dirname(savedPivot)),basename(savedPivot)))(基于SO here上的@malcook回答)
https://stackoverflow.com/questions/37976990
复制相似问题