Use of Leaflet plugins with 'Leaflet for R'

758 views
Skip to first unread message

Thomas

unread,
Apr 19, 2016, 9:43:56 AM4/19/16
to Shiny - Web Framework for R
Hi,

I am in need of data provided through ArcGISOnline and since that stuff doesn't work out of the box with Leaflet I'm in need of some plugin.
Since the plugin exists for the 'normal' Leaflet, I wonder how can I use the plugin with 'Leaflet for R'.

Leaflet -> in particular the 'ESRI Leaflet' plugin seems to be the one needed.

How can I make use of it in 'Leaflet for R'?


Cheers Thomas

Joe Cheng

unread,
Apr 19, 2016, 2:10:42 PM4/19/16
to Thomas, Shiny - Web Framework for R, Bhaskar V. Karambelkar
I've had a hunch for a while that an approach like this would work, just tried it and it does indeed work...
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/6b53737d-7662-4146-b5cc-3b98bb0c2c22%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas

unread,
Apr 20, 2016, 5:15:43 AM4/20/16
to Shiny - Web Framework for R, tb0...@gmail.com, bha...@karambelkar.info
Hi Joe,

thanks for your fast reply and the little example. I have my Leaflet stuff within a dashboard in a single file R app, and was wondering where to place the definitions and functions you showed in your example.

I guess 'esriPlugin' and 'registerPlugin' are not supposed to be within the server-function of the app.
However, if I write the things in between the ui-function and the server-function then I am getting an error of 'unused arguments' that points towards the 'esriPlugin' definition. This is what I wrote to refer to the plugin:

esriPlugin <- htmlDependencies('leaflet.esri',
                               src
= '/leaflet.esri/1.0.3/',
                               script
= 'esri-leaflet.js'
)


registerPlugin
<- function(map, plugin){
  map$dependencies
<- c(map$dependencies, list(plugin))
  map
}

Joe Cheng

unread,
Apr 20, 2016, 10:21:18 AM4/20/16
to Thomas, Shiny - Web Framework for R, bha...@karambelkar.info
It doesn't really matter where you put them--I think the error is because you are calling htmlDependencies instead of htmlDependency.

Satish Regonda

unread,
Oct 19, 2016, 3:36:56 PM10/19/16
to Shiny - Web Framework for R
Using the leads in the discussion, I am trying to use 'leaflet-side-by-side' plugin but no success so far; no errors either. How can I make this work? Thanks, Satish


LeafletSideBySidePlugin <- htmlDependency("leaflet-side-by-side","2.0.0",
                                          src = c(href="https://github.com/digidem/leaflet-side-by-side"),
                                          script="leaflet-side-by-side.js")

# A function that takes a plugin htmlDependency object and adds
# it to the map. This ensures that however or whenever the map
# gets rendered, the plugin will be loaded into the browser.

registerPlugin <- function(map, plugin) {
   map$dependencies <- c(map$dependencies, list(plugin))
   map
}

leaflet() %>% addTiles() %>%
   setView(lng = 12, lat = 50, zoom = 4) %>%
   # Register leaflet-side-by-side plugin on this map instance
   registerPlugin(LeafletSideBySidePlugin) %>%
   onRender("
            function(el, x) {
var mylayer1 = L.tileLayer(
          'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
            maxZoom: 18
            })
var mylayer2 = L.tileLayer(
          '//stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.png',{
            maxZoom: 14
            })
            L.control.sideBySide(mylayer1, mylayer2).addTo(this);
            ")

Reply all
Reply to author
Forward
0 new messages