Contents
How to use a shiny leaflet widget in an app?
Most Shiny output widgets are incorporated into an app by including an output (e.g. plotOutput) for the widget in the UI definition, and using a render function (e.g. renderPlot) in the server function. Leaflet maps are no different; in the UI you call leafletOutput, and on the server side you assign a renderLeaflet call to the output.
What happens when leaflet is redrawn in R?
Inside the renderLeaflet expression, you return a Leaflet map object. This works, but reactive inputs and expressions that affect the renderLeaflet expression will cause the entire map to be redrawn from scratch and reset the map position and zoom level. For some situations that may be acceptable or desirable behavior.
How can I use leaflet and shiny together?
For an extensive example of Shiny and Leaflet working together, take a look at the SuperZip Explorer example app (note the “Get Code” button at the top of the page). (Hint: Try clicking on the bubbles, and also notice that the plots in the sidebar change as you pan and zoom around the map.)
How are shiny output widgets integrated with shiny applications?
The Leaflet package includes powerful and convenient features for integrating with Shiny applications. Most Shiny output widgets are incorporated into an app by including an output (e.g. plotOutput) for the widget in the UI definition, and using a render function (e.g. renderPlot) in the server function.
How to use GeoJSON to create a leaflet?
GeoJSON is becoming a very popular data format among many GIS technologies and services — it’s simple, lightweight, straightforward, and Leaflet is quite good at handling it. In this example, you’ll learn how to create and interact with map vectors created from GeoJSON objects.
How does a leaflet get input from shiny?
Leaflet maps and objects send input values (which we’ll refer to as “events” in this document) to Shiny as the user interacts with them. Object event names generally use this pattern: So for a leafletOutput (“mymap”) had a circle on it, clicking on that circle would update the Shiny input at input$mymap_shape_click.
Do you need a unique layer ID for leaflet?
Layer IDs only need be unique within their category; a call to addCircles will not cause any tile layers to be removed, regardless of layer ID, because circles and tiles are in different categories. Leaflet maps and objects send input values (which we’ll refer to as “events” in this document) to Shiny as the user interacts with them.