R 在传单中使用热图 [英] R using Heatmaps in Leaflet

查看:25
本文介绍了R 在传单中使用热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行 Shiny 的 Linux 机器我正在尝试根据演示 here 运行传单的代码href="http://leaflet.github.io/Leaflet.heat/demo/" rel="nofollow noreferrer">这里 看起来很棒

I have a Linux box that runs Shiny I'm trying to get the code to run for leaflet based on the demos here and here which look brilliant

我的代码如下,取自 rpubs 页面

My code is below which is taken from the rpubs page

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 部分时似乎什么也没发生.

When I run the code above I get the map. My data is good because I can plot the markers, but nothing seems to happen when I add the addWebGLHeatmap portion.

我是 JS 的新手,但是否需要任何其他设置才能使其运行?

I am a complete novice at JS but is there any additional setup I need to get it running?

推荐答案

看来我必须先注册插件才能让它按照 github 页面工作 这里

It seems i have to register the plugin first in order for it to work as per the github page here

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))

这篇关于R 在传单中使用热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆