elbamos / Zeppelin-With-R

Mirror of Apache Zeppelin (Incubating)
Apache License 2.0
45 stars 24 forks source link

charting with leaflet #11

Open smartinsightsfromdata opened 8 years ago

smartinsightsfromdata commented 8 years ago

I tried charting with Leaflet.js in rCharts and with RStudio leaflet library, with no success with either.

Would you be so kind to post an example that works?

Also, have you tried Zeppelin with any htmlwidgets? Do they work? (the method used below, of saving a file and displaying it as iframe was originally proposed by RamnathV as stop gap for jupyter with R kernel - it doesn't work with all htmlwidgets though).

Leaflet The following works with the jupyter notebook and R kernel, but it does not work with Zeppelin R:

library(leaflet)
m <- leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
  # Print the map
tf = 'myfigure.html'
htmlwidgets::saveWidget(m, file = tf, selfcontained = F)
IRdisplay::display_html(paste("<iframe src=' ", tf, " ' ","/>"))

rCharts I tried to display the classic example below, but the chart is displayed on another tab as index.html (on Safari).

%spark.r
# 
library(rCharts)
map3 <- Leaflet$new()
map3$setView(c(51.505, -0.09), zoom = 13)
map3$marker(c(51.5, -0.09), bindPopup = "<p> Hi. I am a popup </p>")
map3$marker(c(51.495, -0.083), bindPopup = "<p> Hi. I am another popup </p>")
map3
elbamos commented 8 years ago

Ok there's two separate issues here so let me address them in turn:

%spark.knitr results='asis',echo=F,warning=F,message=F
require(rCharts)
data(economics, package = 'ggplot2')
econ <- transform(economics, date = as.character(date))
m1 <- mPlot(x = 'date', y = c('psavert', 'uempmed'), type = 'Line',  
  data = econ)
m1$set(pointSize = 0, lineWidth = 1)
m1$show('inline',include_assets=TRUE, cdn=TRUE)

Note a couple of key things -- results are set to 'asis', and the plot is displayed with $show with particular parameters.

This example is from the demo notebook. That was included before, but isn't in the current version that's pending merge into zeppelin. So the instructions for doing this should probably get added to the manual

If you can suggest an acceptably-licensed R or java/scala library that can handle it, I'll write the code to bridge them together.


I'm going to leave this issue open for a few days in case you run into any problems with rCharts

ramnathv commented 8 years ago

@elbamos here is one thought. if widget authors can also provide standalone versions of assets (pre-run through pandoc), then it is fairly trivial to write a dependency bundler in R that inlines all assets. The question is will widget authors be willing to add extra assets to their packages?