我有一个运行 Shiny 的 Linux 机器
我正在尝试根据演示获取传单运行的代码here https://rpubs.com/bhaskarvk/leaflet-heatmap and here http://leaflet.github.io/Leaflet.heat/demo/看起来很漂亮
我的代码如下,取自 rpubs 页面
library(leaflet)
library(leaflet.extras)
leaflet(quakes) %>% addProviderTiles(providers$CartoDB.DarkMatter) %>%
addWebGLHeatmap(lng=~long, lat=~lat, intensity = ~mag, size=60000)
我已经安装了/home/shiny/nodejs/Leaflet.heat-gh-pages
当我运行上面的代码时,我得到了地图。我的数据很好,因为我可以绘制标记,但是当我添加addWebGLHeatmap
部分。
我是一个完全的新手JS
但是我需要进行任何额外的设置才能让它运行吗?
看来我必须先注册插件才能使其按照 github 页面工作here https://gist.github.com/jcheng5/c084a59717f18e947a17955007dc5f92
library(leaflet)
library(htmltools)
library(htmlwidgets)
library(dplyr)
heatPlugin <- htmlDependency("Leaflet.heat", "99.99.99",
src = c(href = "http://leaflet.github.io/Leaflet.heat/dist/"),
script = "leaflet-heat.js"
)
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}
leaflet() %>% addTiles() %>%
fitBounds(min(quakes$long), min(quakes$lat), max(quakes$long), max(quakes$lat)) %>%
registerPlugin(heatPlugin) %>%
onRender("function(el, x, data) {
data = HTMLWidgets.dataframeToD3(data);
data = data.map(function(val) { return [val.lat, val.long, val.mag*100]; });
L.heatLayer(data, {radius: 25}).addTo(this);
}", data = quakes %>% select(lat, long, mag))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)