简体   繁体   中英

R using Heatmaps in Leaflet

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

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)

I have installed /home/shiny/nodejs/Leaflet.heat-gh-pages

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM