When I try to install a package named "leaflet", the dialog with CRAN only shows a package named leafletR
. Installing and loading that package does succeed with a message to the console:
Your leaflet map has been saved under /Users/myuser_name/map/map.html
And that map has the desired functionality. Given the amount of information that I can access from the web browser, I'm guessing that I'm actually interfaced through Chrome to an OpenStreetMap server rather than interacting with a disk file data service.
There is no addTiles function in the version downloaded from CRAN. And using sos::findFn does not find it in any other package. This could be a new function only available in the github version:
https://github.com/chgrl/leafletR
Further searching shows this to be only hosted on RStudio and not on CRAN: http://robinlovelace.net/r/2015/02/01/leaflet-r-package.html
I needed a fresh session since I was getting error that I suspected were cause by having both leaflet and leafletR loaded at the same time. In my browser I left-clicked to bring up a ViewSource window and then selected and copy below. Both Chrome and Firefox have the capacity to display the underlying code and support selection and copying to an editor.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script src="lib/htmlwidgets-0.3.2/htmlwidgets.js"></script>
<script src="lib/jquery-1.11.1/jquery.min.js"></script>
<link href="lib/leaflet-0.7.3/leaflet.css" rel="stylesheet" />
<script src="lib/leaflet-0.7.3/leaflet.js"></script>
<link href="lib/leafletfix-1.0.0/leafletfix.css" rel="stylesheet" />
<script src="lib/leaflet-binding-0.0.16/leaflet.js"></script>
</head>
<body style="background-color:white;">
<div id="htmlwidget_container">
<div id="htmlwidget-3689" style="width:100%;height:400px;" class="leaflet"></div>
</div>
<script type="application/json" data-for="htmlwidget-3689">{ "x": {
"calls": [
{
"method": "addTiles",
"args": [
"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
null,
{
"minZoom": 0,
"maxZoom": 18,
"maxNativeZoom": null,
"tileSize": 256,
"subdomains": "abc",
"errorTileUrl": "",
"tms": false,
"continuousWorld": false,
"noWrap": false,
"zoomOffset": 0,
"zoomReverse": false,
"opacity": 1,
"zIndex": null,
"unloadInvisibleTiles": null,
"updateWhenIdle": null,
"detectRetina": false,
"reuseTiles": false,
"attribution": "© <a href=\"http://openstreetmap.org\">OpenStreetMap</a> contributors, <a href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA</a>"
}
]
}
]
},"evals": [ ] }</script>
<script type="application/htmlwidget-sizing" data-for="htmlwidget-3689">{ "viewer": {
"width": "100%",
"height": 400,
"padding": 0,
"fill": true
},"browser": {
"width": "100%",
"height": 400,
"padding": 0,
"fill": true
} }</script>
</body>
</html>
The code alone is not enough. The rest of the required support files will be saved in a directory with the same name as the html file and the browser "Save As ..." function is best for that:
