render_ipyleaflet
render_ipyleaflet class
Reactively render an ipyleaflet map.
Usage Source
render_ipyleaflet(
_fn: Optional[ValueFn[ValueT]] = None,
*,
width: Optional[str] = None,
height: Optional[str] = None,
fill: Optional[bool] = None,
fillable: Optional[bool] = None,
rate_policy: Optional[RatePolicy] = None,
rate_delay: Optional[float] = None,
)@render_ipyleaflet is a decorator that creates a render function – a function that returns the map to display and re-runs when the reactive values it reads change:
import ipyleaflet
from shinywidgets import render_ipyleaflet
@render_ipyleaflet
def map():
return ipyleaflet.Map(center=(51.48, 0), zoom=12)The render function should return an ipyleaflet.Map (requires pip install ipyleaflet) or a subclass of it, such as a leafmap.leafmap.Map.
In a filling layout, the map fills its container unless it has its own height (e.g., Layout(height="300px")). Default heights set by a subclass (e.g., leafmap’s 600px) are treated as unset.
Note
Accessing the rendered widget: the render function gains two read-only attributes: .value, the value it most recently returned, and .widget, the rendered Map instance. Map state can also be read reactively with .read("some_trait") (a shortcut for reactive_read() on .widget).
Responding to user interaction: read the map’s accessors in a reactive function (a @render.* function, @reactive.calc, or @reactive.effect), which re-runs whenever the user gestures, much like input.my_slider():
map.bounds(): the viewport,((south, west), (north, east)).map.zoom()andmap.center(): the camera.map.clicked(): the most recent map click.map.drawn_features(): the shapes drawn on the map’s DrawControl.
Coordinates are [lat, lng], as ipyleaflet reports them (lonboard is (lng, lat)). The accessors can’t be read inside this output’s own render function, which builds a new map each time it runs. For anything beyond them, use map.read() (a shortcut for reactive_read() on map.widget).
Mutating the widget: use .widget to update the rendered map in place (e.g., change its zoom or center, or add layers); trait changes on the widget are synced to the browser.
Parameters
width : Optional[str] = None-
A CSS length unit (e.g.,
"400px"or"100%") for the output’s width. height : Optional[str] = None-
A CSS length unit for the output’s height. When
None(the default), the output is designed to fill the height of its parent container (seefillandfillable). fill : Optional[bool] = None-
Whether the output should grow or shrink to fit its parent container. When
None(the default), this isTrueifheightis not specified. fillable : Optional[bool] = None-
Whether the output container should fill available space (scrolling its contents on overflow). When
None(the default), this isTrueifheightis not specified. rate_policy : Optional[RatePolicy] = None-
How to rate-limit
reactive_read()on the widget:"debounce"or"throttle".None(the default) debouncesreactive_read()only ifrate_delayis given; no accessor on this renderer declares a default. rate_delay : Optional[float] = None-
The rate-limit window in seconds (default 0.25).
0disables rate limiting. Each :which :
See also
output_widget(): in Shiny Core, the UI needs this to hold the output (Shiny Express displays it where the render function is defined).