title: Heatmap on Zeppelin using Leaflet
body: <p>I want to add a heatmap to a Zeppelin paragraph using Leaflet with R. I wrote a script in R Studio which works fine, but when I migrate to Zeppelin the heatmap is not showing. Here is my code in R Studio</p>
  
  <pre><code>map3 &lt;- Leaflet$new()
  map3$setView(c(29.7632836,  -95.3632715), 10)
  
  vector &lt;- c( list(c(29.76,-95.36, 50)), list(c(29.77, -95.37, 50)), list(c(29.75,-95.39,50)))
  #vector = toJSONArray2(na.omit(vector), json = F, names = F)
  cat(rjson::toJSON(vector[1:3]))
  
  map3$addAssets(jshead = c(
    "http://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js"
  ))
  
  map3$addAssets(jshead = c("http://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js"))
  map3$setTemplate(afterScript = sprintf("
      &lt;script&gt;
        var addressPoints = %s
        var heat = L.heatLayer(addressPoints).addTo(map)           
      &lt;/script&gt;"
                                         ,rjson::toJSON(vector)))
  
  map3
  </code></pre>
  
  <p>My code in Zeppelin is almost identical. Only the input and the output method changes:</p>
  
  <pre><code>library(SparkR)
  
  sparkcontext &lt;- sparkR.init("local[4]","cvspark",sparkEnvir=list(spark.executor.memory="1g"))
  
  #sparkR.session()
  positions &lt;- sql("SELECT lat, long FROM my_table")
  pos &lt;- collect(positions)
  
  map3 &lt;- Leaflet$new()
  
  map3$setView(c(39.93, 32.85))
  
  vector &lt;- c()
  values1 &lt;- pos[[1]]
  values2 &lt;- pos[[2]]
  for (i in 1:length(values1))
    vector &lt;- c(vector, list(c(values1[i], values2[i], 1000)))
  
  cat(rjson::toJSON(vector[1:3]))
  
  map3$addAssets(jshead = c("http://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js"))
  map3$setTemplate(afterScript = sprintf("
      &lt;script&gt;
        var addressPoints = %s
        var heat = L.heatLayer(addressPoints).addTo(map)           
      &lt;/script&gt;"
      ,rjson::toJSON(vector)))
  
  
  map3$print("map3", include_assets=TRUE, cdn=TRUE)
  </code></pre>
  
  <p>The following code shows the inputs are identical:</p>
  
  <pre><code>cat(rjson::toJSON(vector[1:3]))
  </code></pre>
  
  <p>R Studio output:</p>
  
  <pre><code>[[29.76,-95.36,50],[29.77,-95.37,50],[29.75,-95.39,50]],
  </code></pre>
  
  <p>Zeppelin output:</p>
  
  <pre><code>[[41.6406843380063,37.6892873258843,1000],[37.0194101218466,30.3908073266391,1000],[34.0236444385`445,40.5599139822316,1000]]
  </code></pre>
  
  <p>The problem here is <code>map3$print("map3", include_assets=TRUE, cdn=TRUE)</code> does not include the heatmap layer in its output. In order to show the map on Zeppelin, as far as I know, this method has to be called. The question is: How do we make the print method include the javascript code which enables the heatmap layer on the map.</p>
  
  <p>Also I get the following error in Zeppelin. But I don't think it is relevant to this question:</p>
  
  <pre><code>Error in sparkR.sparkContext(master, appName, sparkHome, convert`NamedListToEnv(sparkEnvir), : JVM is not ready after 10 seconds
  </code></pre>