在地理坐標之外,我想在城市地圖上繪制簡單的普通點并將輸出保存為.png。我在Linux Ubuntu 22.04LTS上。對于第一部分,我找到了一個非常簡短直接的leaflet解決方案。
library(leaflet); library(htmlwidgets); library(webshot)
m <- leaflet() %>%
addTiles("https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png") %>%
setView(-.12, 51.50, zoom=13)
m$x$options <- append(m$x$options, list("zoomControl" = FALSE))
m <- m %>%
addCircleMarkers(c(-.11, -.12, -.13), c(51.48, 51.52, 51.50),
radius=1, color="red")
m

但是,第二部分,保存.png失敗。我試過這個解決方案,
saveWidget(m, "temp.html", selfcontained=TRUE)
webshot("temp.html", file="Rplot.png", cliprect="viewport")
但是 - 使用phantomjs 2.1.1- 它給了我這些錯誤:
Auto configuration failed
139740646049728:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:185:filename(libproviders.so): libproviders.so: cannot open shared object file: No such file or directory
139740646049728:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
139740646049728:error:0E07506E:configuration file routines:MODULE_LOAD_DSO:error loading dso:conf_mod.c:285:module=providers, path=providers
139740646049728:error:0E076071:configuration file routines:MODULE_RUN:unknown module name:conf_mod.c:222:module=providers
Error in webshot("temp.html", file = "Rplot.png", cliprect = "viewport") :
webshot.js returned failure value: 1
In addition: Warning message:
In is.null(x) || is.na(x) : 'length(x) = 4 > 1' in coercion to 'logical(1)'
使用稍舊的版本phantomjs 1.9.8沒有錯誤,但影像完全空白。我使用這些源phantomjs在 Ubuntu 上安裝:1.9.8、2.1.1。我查看了這個答案,根據它你必須安裝開發版本,但我沒有發現它有用,因為我不知道開發版本的phantomjs.
我不一定需要互動式leaflet,但我認為黑暗主題看起來很酷,并且對應于夜間犯罪的研究主題。因此,如果它看起來相似(如果它不使用 Google),我對靜態解決方案持開放態度。
uj5u.com熱心網友回復:
使用新包webshot2,它使用 Chrome 或 Chromium 無頭瀏覽器而不是phantomjs。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/490106.html
