ramnathv / rMaps

Interactive Maps from R
http://rmaps.github.io
389 stars 194 forks source link

Leaflet Heatmap doesn't work with Shiny #101

Closed sherrylau closed 8 years ago

sherrylau commented 8 years ago

Hi,

I was using rMap to create a leaflet heatmap with my data. It works fine when I am running the code locally like:

    input_data = toJSONArray2(na.omit(input_data),json=F,names=F)
    L2 = Leaflet$new()
    L2$setView(c(39.72453,-81.1361),zoom=8)
    L2$tileLayer(provider="MapQuestOpen.OSM")
    L2$addAssets(jshead=c("http://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js"))
    L2$setTemplate(afterScript=sprintf("
      <script>
        var addressPoints = %s
        var heat = L.heatLayer(addressPoints).addTo(map)     
      </script>
    ",rjson::toJSON(input_data)))
    L2

It works fine and i can see the leaflet map and heatmap.

When i run it with shiny:

shinyUI(
  dashboardPage(skin=c("black"),
                dashboardHeader("GeoHeatMap")),
                dashboardSidebar(disable=TRUE),
                dashboardBody(
                  fluidRow(
                    tabBox(title="GeoSpatial HeatMap", width=12, 
                      tabPanel("Map",chartOutput("geoHeatMap","leaflet"))
                    )
                  ))
  ))
shinyServer(function(input,output){
  output$geoHeatMap = renderMap({
    input_data = toJSONArray2(na.omit(input_data),json=F,names=F)
    L2 = Leaflet$new()
    L2$setView(c(39.72453,-81.1361),zoom=8)
    L2$tileLayer(provider="MapQuestOpen.OSM")
    L2$addAssets(jshead=c("http://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js"))
    L2$setTemplate(afterScript=sprintf("
      <script>
        var addressPoints = %s
        var heat = L.heatLayer(addressPoints).addTo(map)     
      </script>
    ",rjson::toJSON(input_data)))
    L2
  })
})

It renders the map only without the heat part.

Can you help me with this issue?

Thanks, Sherry

ramnathv commented 8 years ago

I would recommend taking a look at the leaflet package by rstudio, which has a more advanced implementation with all the plugins you mention.

NahuelGrasso commented 7 years ago

does the leaflet package by rstudio provide a tool for heatmaps?