| Title: | Interactive & Customisable Maps using the 'MapLibre GL JS' Library |
|---|---|
| Description: | Create interactive maps that can keep up with complex visualisations and large datasets, with this useful interface to the 'MapLibre GL JS' (<https://maplibre.org/maplibre-gl-js/docs/>) library. Users can create maps directly in the console, or as an HTML widget within 'Shiny' web applications, and render spatial data quickly with many customisable options (clusters, custom icons, map layers, and backgrounds). The goal of the package is to make it easier to interpret and explore large spatial datasets within the context of a 'Shiny' dashboard, without having long loading times waiting for a map to update with new data. |
| Authors: | Poppy Pakinui [aut, cre], Jocelyn Qian [ctb], Nick Snellgrove [ctb], MapLibre contributors [cph] (MapLibre GL JS library), Turf contributors [cph] (turf plugin), Mapbox contributors [cph] (mapbox-gl-draw plugin), epi [cph, fnd] |
| Maintainer: | Poppy Pakinui <[email protected]> |
| License: | AGPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-05-07 20:22:49 UTC |
| Source: | https://github.com/cran/toro |
Adds play/pause/stop buttons to control route animations on the map. Optionally includes a speed control slider for adjusting animation speed.
add_animation_controls( map, route_id = NULL, position = "top-right", panel_id = NULL, buttons = c("play", "pause"), include_speed_control = FALSE, speed_values = c(0.5, 1, 2), speed_labels = c("Slow", "Normal", "Fast"), settings = list() )add_animation_controls( map, route_id = NULL, position = "top-right", panel_id = NULL, buttons = c("play", "pause"), include_speed_control = FALSE, speed_values = c(0.5, 1, 2), speed_labels = c("Slow", "Normal", "Fast"), settings = list() )
map |
A toro map object or a map proxy object. |
route_id |
Optional route ID to control. If NULL, controls all routes. |
position |
Position of the controls on the map. Default is "top-right". |
panel_id |
Optional control panel ID to add controls to instead of map. |
buttons |
Character vector of buttons to include. Options: "play", "pause", "stop". Default is c("play", "pause"). |
include_speed_control |
Logical. Whether to include a speed control slider. Default is FALSE. |
speed_values |
Numeric vector of speed values for the speed slider. Default is c(0.5, 1, 2) for slow, normal, and fast speeds. |
speed_labels |
Character vector of labels for speed values. Default is c("Slow", "Normal", "Fast"). |
settings |
A list of additional settings for the controls. |
The map or map proxy object for chaining.
library(sf) line_data <- sf::st_sf( id = 1, geometry = sf::st_sfc( sf::st_linestring( cbind(c(172.2041, 163.9383), c(-32.56960, -46.43999)) ), crs = 4326 ) ) map() |> add_route(route_id = "route_line", points = line_data) |> add_animation_controls(route_id = "route_line", include_speed_control = TRUE)library(sf) line_data <- sf::st_sf( id = 1, geometry = sf::st_sfc( sf::st_linestring( cbind(c(172.2041, 163.9383), c(-32.56960, -46.43999)) ), crs = 4326 ) ) map() |> add_route(route_id = "route_line", points = line_data) |> add_animation_controls(route_id = "route_line", include_speed_control = TRUE)
Add a circle layer to a map or map proxy
add_circle_layer( map, id, source, paint = NULL, layout = NULL, popup_column = NULL, hover_column = NULL, can_cluster = FALSE, under_id = NULL, filter = NULL, ... )add_circle_layer( map, id, source, paint = NULL, layout = NULL, popup_column = NULL, hover_column = NULL, can_cluster = FALSE, under_id = NULL, filter = NULL, ... )
map |
The map object or map proxy to which the layer will be added. |
id |
A unique identifier for the layer. |
source |
The data source for the layer, if not a GeoJSON, it will be converted. |
paint |
A list of paint options for styling the layer. See |
layout |
A list of layout options for the layer. See |
popup_column |
The column name to use for popups. Default is |
hover_column |
The column name to use for hover effects. Default is |
can_cluster |
Whether the layer can be clustered. Default is |
under_id |
The ID of an layer already on the map to place this layer under.
Default is |
filter |
A filter expression to apply to the layer. Default is |
... |
Additional arguments to include in the layer definition.
|
The updated map object with the circle layer added.
# Load libraries library(spData) library(sf) nz_data <- spData::nz_height |> sf::st_transform(4326) map() |> set_bounds(bounds = nz_data) |> add_circle_layer( id = "nz_elevation", source = nz_data, hover_column = "elevation" ) map() |> set_bounds(bounds = nz_data) |> add_circle_layer( id = "nz_elevation", source = nz_data, hover_column = "elevation", paint = get_paint_options( "circle", options = list( colour = get_column_steps( "elevation", c(3000), c("grey", "black") ) ) ) )# Load libraries library(spData) library(sf) nz_data <- spData::nz_height |> sf::st_transform(4326) map() |> set_bounds(bounds = nz_data) |> add_circle_layer( id = "nz_elevation", source = nz_data, hover_column = "elevation" ) map() |> set_bounds(bounds = nz_data) |> add_circle_layer( id = "nz_elevation", source = nz_data, hover_column = "elevation", paint = get_paint_options( "circle", options = list( colour = get_column_steps( "elevation", c(3000), c("grey", "black") ) ) ) )
Creates a toggle button that can enable/disable clustering for a specific layer.
add_cluster_toggle( map, layer_id, control_id = NULL, left_label = "Toggle Clustering", right_label = NULL, initial_state = FALSE, position = "top-right", panel_id = NULL, section_title = NULL, group_id = NULL )add_cluster_toggle( map, layer_id, control_id = NULL, left_label = "Toggle Clustering", right_label = NULL, initial_state = FALSE, position = "top-right", panel_id = NULL, section_title = NULL, group_id = NULL )
map |
The map or map proxy object. |
layer_id |
ID of the layer to toggle clustering for. |
control_id |
ID for the control. If |
left_label |
Label text for the toggle button. Default is "Toggle Clustering". |
right_label |
Label text for the toggle button when clustering is off. Default is "Clustering Off". |
initial_state |
Initial clustering state. Default is |
position |
Position on the map if not using a control panel. Default is "top-right". |
panel_id |
ID of control panel to add to (optional). |
section_title |
Section title when added to a control panel. |
group_id |
ID of control group to add to (optional). |
The map or map proxy object for chaining.
# Load libraries library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) map() |> add_symbol_layer( id = "quakes", source = quakes_data, can_cluster = TRUE ) |> add_cluster_toggle(layer_id = "quakes")# Load libraries library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) map() |> add_symbol_layer( id = "quakes", source = quakes_data, can_cluster = TRUE ) |> add_cluster_toggle(layer_id = "quakes")
Creates a collapsible group within a control panel that can contain multiple controls.
add_control_group( map, panel_id, group_id, group_title = NULL, collapsible = FALSE, collapsed = FALSE )add_control_group( map, panel_id, group_id, group_title = NULL, collapsible = FALSE, collapsed = FALSE )
map |
The map or map proxy object. |
panel_id |
ID of the target control panel. |
group_id |
Unique identifier for the control group. |
group_title |
Title for the control group (optional). |
collapsible |
Whether the group can be collapsed. Default is FALSE. |
collapsed |
Initial collapsed state. Default is FALSE. |
The map or map proxy object for chaining.
map() |> add_control_panel(panel_id = "my_panel", direction = "row") |> add_control_group( panel_id = "my_panel", group_id = "group_1", group_title = "Group 1" ) |> add_control_group( panel_id = "my_panel", group_id = "group_2", group_title = "Group 2" ) |> add_cursor_coords_control(panel_id = "my_panel", group_id = "group_1") |> add_zoom_control(panel_id = "my_panel", group_id = "group_2") map() |> add_control_panel( panel_id = "my_panel", title = "Map Settings", position = "top-right", collapsible = TRUE, collapsed = TRUE, direction = "row" ) |> add_cursor_coords_control( panel_id = "my_panel", section_title = "Cursor Coordinates" )map() |> add_control_panel(panel_id = "my_panel", direction = "row") |> add_control_group( panel_id = "my_panel", group_id = "group_1", group_title = "Group 1" ) |> add_control_group( panel_id = "my_panel", group_id = "group_2", group_title = "Group 2" ) |> add_cursor_coords_control(panel_id = "my_panel", group_id = "group_1") |> add_zoom_control(panel_id = "my_panel", group_id = "group_2") map() |> add_control_panel( panel_id = "my_panel", title = "Map Settings", position = "top-right", collapsible = TRUE, collapsed = TRUE, direction = "row" ) |> add_cursor_coords_control( panel_id = "my_panel", section_title = "Cursor Coordinates" )
Creates a flexible control panel that can contain multiple controls.
add_control_panel( map, panel_id, title = NULL, position = "bottom-left", collapsible = FALSE, collapsed = FALSE, direction = "column", custom_controls = NULL )add_control_panel( map, panel_id, title = NULL, position = "bottom-left", collapsible = FALSE, collapsed = FALSE, direction = "column", custom_controls = NULL )
map |
The map or map proxy object. |
panel_id |
Unique identifier for the control panel. |
title |
Title for the control panel. If NULL, no title is shown. |
position |
Position of the control panel on the map. Default is "bottom-left". Options include "top-left", "top-right", "bottom-left", "bottom-right". |
collapsible |
Whether the panel can be collapsed. Default is FALSE. |
collapsed |
Initial collapsed state. Default is FALSE. |
direction |
Layout direction for controls within the panel. Either "row" or "column". Default is "column". |
custom_controls |
List of custom controls to add initially. Each should be a list with elements: html, id (optional), title (optional). |
The map or map proxy object for chaining.
map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_cursor_coords_control(panel_id = "my_panel") |> add_zoom_control(panel_id = "my_panel") map() |> add_control_panel( panel_id = "my_panel", title = "Map Settings", position = "top-right", collapsible = TRUE, collapsed = TRUE, direction = "row" ) |> add_cursor_coords_control( panel_id = "my_panel", section_title = "Cursor Coordinates" )map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_cursor_coords_control(panel_id = "my_panel") |> add_zoom_control(panel_id = "my_panel") map() |> add_control_panel( panel_id = "my_panel", title = "Map Settings", position = "top-right", collapsible = TRUE, collapsed = TRUE, direction = "row" ) |> add_cursor_coords_control( panel_id = "my_panel", section_title = "Cursor Coordinates" )
Add a cursor coordinates control to the map
add_cursor_coords_control( map, position = "bottom-left", long_label = "Lng", lat_label = "Lat", panel_id = NULL, section_title = NULL, group_id = NULL )add_cursor_coords_control( map, position = "bottom-left", long_label = "Lng", lat_label = "Lat", panel_id = NULL, section_title = NULL, group_id = NULL )
map |
The map or map proxy object. |
position |
The position of the cursor coordinates control on the map.
Default is |
long_label |
The label for the longitude coordinate. Default is |
lat_label |
The label for the latitude coordinate. Default is |
panel_id |
ID of control panel to add to (optional). |
section_title |
Section title when added to a control panel. |
group_id |
ID of control group to add to (optional). |
The map or map proxy object for chaining.
# Add to a map map() |> add_cursor_coords_control() # Change default options map() |> add_cursor_coords_control( position = "top-right", long_label = "Longitude", lat_label = "Latitude" ) # Add to a control panel map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_cursor_coords_control(panel_id = "my_panel", section_title = "Cursor Coordinates") # Add to a control panel inside a control group map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_control_group( panel_id = "my_panel", group_id = "map_state", group_title = "Map State" ) |> add_cursor_coords_control(panel_id = "my_panel", group_id = "map_state")# Add to a map map() |> add_cursor_coords_control() # Change default options map() |> add_cursor_coords_control( position = "top-right", long_label = "Longitude", lat_label = "Latitude" ) # Add to a control panel map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_cursor_coords_control(panel_id = "my_panel", section_title = "Cursor Coordinates") # Add to a control panel inside a control group map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_control_group( panel_id = "my_panel", group_id = "map_state", group_title = "Map State" ) |> add_cursor_coords_control(panel_id = "my_panel", group_id = "map_state")
Add a custom HTML control to the map
add_custom_control( map, id, html, position = "top-right", panel_id = NULL, section_title = NULL, group_id = NULL )add_custom_control( map, id, html, position = "top-right", panel_id = NULL, section_title = NULL, group_id = NULL )
map |
The map or map proxy object. |
id |
The ID for the custom control. |
html |
The HTML content to add as a control. |
position |
The position of the control on the map. Default is |
panel_id |
ID of control panel to add to (optional). |
section_title |
Section title when added to a control panel. |
group_id |
ID of control group to add to (optional). |
The map or map proxy object for chaining.
# Add to a map map() |> add_custom_control( id = "custom_control", html = "<p>I am a custom control</p>" ) # Add to a control panel map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_custom_control( id = "custom_control_panel", html = "<p>I am a custom control in a panel</p>", panel_id = "my_panel", section_title = "Custom Control Section" ) # Add to a control panel inside a control group map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_control_group( panel_id = "my_panel", group_id = "custom_controls", group_title = "Custom Controls" ) |> add_custom_control( id = "custom_control_panel", html = "<p>I am a custom control in a panel</p>", panel_id = "my_panel", group_id = "custom_controls" )# Add to a map map() |> add_custom_control( id = "custom_control", html = "<p>I am a custom control</p>" ) # Add to a control panel map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_custom_control( id = "custom_control_panel", html = "<p>I am a custom control in a panel</p>", panel_id = "my_panel", section_title = "Custom Control Section" ) # Add to a control panel inside a control group map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_control_group( panel_id = "my_panel", group_id = "custom_controls", group_title = "Custom Controls" ) |> add_custom_control( id = "custom_control_panel", html = "<p>I am a custom control in a panel</p>", panel_id = "my_panel", group_id = "custom_controls" )
The draw control allows users to draw shapes (polygons, lines, points) on the map.
The drawn shapes can be styled and managed through the control options.
Information about the drawn shapes can be retrieved in Shiny using the
input$map_shape_created (where map is the ID of the map) reactive value.
add_draw_control( map, id = "draw_control", position = "top-right", modes = c("polygon"), active_colour = "#04AAC1", inactive_colour = "#04AAC1", mode_labels = list(), panel_id = NULL, section_title = NULL, group_id = NULL )add_draw_control( map, id = "draw_control", position = "top-right", modes = c("polygon"), active_colour = "#04AAC1", inactive_colour = "#04AAC1", mode_labels = list(), panel_id = NULL, section_title = NULL, group_id = NULL )
map |
The map or map proxy object. |
id |
The ID for the draw control. |
position |
The position of the draw control on the map. Default is |
modes |
A vector of modes to enable in the draw control. Default is |
active_colour |
The colour for the drawn shapes. Default is |
inactive_colour |
The colour for the inactive shapes. Default is |
mode_labels |
A named list of labels for each mode.
For example, |
panel_id |
ID of control panel to add to (optional). |
section_title |
Section title when added to a control panel. |
group_id |
Optional group ID for grouping controls within a panel. |
For a more in-depth example see the Draw control article.
The map or map proxy object for chaining.
get_drawn_shape() to retrieve the drawn shape as an sf object in Shiny.
map() |> add_draw_control()map() |> add_draw_control()
Add a FeatureService source to the map
add_feature_server_source( map, source_url, source_id, append_query_url = "/0/query?where=1=1&outFields=*&f=geojson" )add_feature_server_source( map, source_url, source_id, append_query_url = "/0/query?where=1=1&outFields=*&f=geojson" )
map |
The map or map proxy object. |
source_url |
The URL of the FeatureService source. |
source_id |
The ID for the source. |
append_query_url |
The query URL to append to the source URL. Default is
|
The map or map proxy object for chaining.
By default the function appends a query URL to the provided source_url to retrieve all
features in GeoJSON format. If you need more control over the query parameters, you can
provide the full query URL directly in the source_url argument and set append_query_url
to an empty string to prevent appending the default query parameters.
service_url <- paste0( "https://services1.arcgis.com/VwarAUbcaX64Jhub/arcgis/rest/services/", "World_Exclusive_Economic_Zones_Boundaries/FeatureServer" ) map() |> add_feature_server_source(service_url, "eez") |> add_line_layer(id = "eez_lines", source = "eez")service_url <- paste0( "https://services1.arcgis.com/VwarAUbcaX64Jhub/arcgis/rest/services/", "World_Exclusive_Economic_Zones_Boundaries/FeatureServer" ) map() |> add_feature_server_source(service_url, "eez") |> add_line_layer(id = "eez_lines", source = "eez")
Add a fill layer to a map or map proxy
add_fill_layer( map, id, source, paint = NULL, layout = NULL, popup_column = NULL, hover_column = NULL, can_cluster = FALSE, under_id = NULL, filter = NULL, ... )add_fill_layer( map, id, source, paint = NULL, layout = NULL, popup_column = NULL, hover_column = NULL, can_cluster = FALSE, under_id = NULL, filter = NULL, ... )
map |
The map object or map proxy to which the layer will be added. |
id |
A unique identifier for the layer. |
source |
The data source for the layer, if not a GeoJSON, it will be converted. |
paint |
A list of paint options for styling the layer. See |
layout |
A list of layout options for the layer. See |
popup_column |
The column name to use for popups. Default is |
hover_column |
The column name to use for hover effects. Default is |
can_cluster |
Whether the layer can be clustered. Default is |
under_id |
The ID of an layer already on the map to place this layer under.
Default is |
filter |
A filter expression to apply to the layer. Default is |
... |
Additional arguments to include in the layer definition.
|
The updated map object with the fill layer added.
# Load libraries library(dplyr) library(spData) library(sf) nz_data <- spData::nz |> dplyr::rename(geometry = geom) |> sf::st_transform(4326) map() |> add_fill_layer( id = "nz_regions", source = nz_data, hover_column = "Name" ) map() |> add_fill_layer( id = "nz_regions", source = nz_data, hover_column = "Name", paint = get_paint_options( "fill", options = list( colour = "#a3b18a", opacity = 0.3, outline_colour = "#588157" ) ) )# Load libraries library(dplyr) library(spData) library(sf) nz_data <- spData::nz |> dplyr::rename(geometry = geom) |> sf::st_transform(4326) map() |> add_fill_layer( id = "nz_regions", source = nz_data, hover_column = "Name" ) map() |> add_fill_layer( id = "nz_regions", source = nz_data, hover_column = "Name", paint = get_paint_options( "fill", options = list( colour = "#a3b18a", opacity = 0.3, outline_colour = "#588157" ) ) )
Add an image source to the map
add_image(map, image_id, image_url)add_image(map, image_id, image_url)
map |
The map or map proxy object. |
image_id |
The ID of the image source. |
image_url |
The URL of the image to add. |
The map or map proxy object for chaining.
# Load libraries library(sf) # Prepare data data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) image_url <- paste0( "https://upload.wikimedia.org/wikipedia/en/thumb/0/02/", "Leaf_icon.png/600px-Leaf_icon.png" ) map() |> add_image( image_id = "leaf-icon", image_url = image_url ) |> add_symbol_layer( id = "leaf_symbols", source = sf::st_as_sf(quakes_data, coords = c("long", "lat"), crs = 4326), layout = get_layout_options( "symbol", options = list( icon_image = "leaf-icon", icon_size = 0.1 ) ) )# Load libraries library(sf) # Prepare data data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) image_url <- paste0( "https://upload.wikimedia.org/wikipedia/en/thumb/0/02/", "Leaf_icon.png/600px-Leaf_icon.png" ) map() |> add_image( image_id = "leaf-icon", image_url = image_url ) |> add_symbol_layer( id = "leaf_symbols", source = sf::st_as_sf(quakes_data, coords = c("long", "lat"), crs = 4326), layout = get_layout_options( "symbol", options = list( icon_image = "leaf-icon", icon_size = 0.1 ) ) )
Add a grid of latitude and longitude lines to the map
add_lat_lng_grid(map, grid_colour = "#000000")add_lat_lng_grid(map, grid_colour = "#000000")
map |
The map or map proxy object. |
grid_colour |
The colour of the grid lines. Default is |
The map or map proxy object for chaining.
map() |> add_lat_lng_grid()map() |> add_lat_lng_grid()
Add a layer to a map or map proxy
add_layer( map, id, type = "fill", source, paint = NULL, layout = NULL, popup_column = NULL, hover_column = NULL, can_cluster = FALSE, under_id = NULL, filter = NULL, ... )add_layer( map, id, type = "fill", source, paint = NULL, layout = NULL, popup_column = NULL, hover_column = NULL, can_cluster = FALSE, under_id = NULL, filter = NULL, ... )
map |
The map object or map proxy to which the layer will be added. |
id |
A unique identifier for the layer. |
type |
The type of layer to add (e.g., "fill", "circle", "line"). Default is "fill". |
source |
The data source for the layer, if not a GeoJSON, it will be converted. |
paint |
A list of paint options for styling the layer. See |
layout |
A list of layout options for the layer. See |
popup_column |
The column name to use for popups. Default is |
hover_column |
The column name to use for hover effects. Default is |
can_cluster |
Whether the layer can be clustered. Default is |
under_id |
The ID of an layer already on the map to place this layer under.
Default is |
filter |
A filter expression to apply to the layer. Default is |
... |
Additional arguments to include in the layer definition.
|
The updated map object with the new layer added.
If source is not a string referring to an existing source, it will be converted to a
GeoJSON source and added to the map automatically. The Id for the source is generated by
appending the layer Id to source-. For example, if you add a layer with id = "my_layer"
and source is a sf object, the source is added to the map with the ID "source-my_layer".
get_paint_options() for paint customisation, get_layout_options() for layout
customisation, and get_layer_filter() for applying filters to layers.
# Load libraries library(spData) library(dplyr) library(sf) nz_data <- spData::nz |> dplyr::rename(geometry = geom) |> sf::st_transform(4326) map() |> add_layer( id = "nz_regions", type = "fill", source = nz_data, hover_column = "Name" )# Load libraries library(spData) library(dplyr) library(sf) nz_data <- spData::nz |> dplyr::rename(geometry = geom) |> sf::st_transform(4326) map() |> add_layer( id = "nz_regions", type = "fill", source = nz_data, hover_column = "Name" )
Creates a drop-down selector that allows switching between layers, showing only the selected layer while hiding all others. This is useful for comparing different data layers or allowing users to choose between mutually exclusive visualizations.
add_layer_selector_control( map, layer_ids, labels = NULL, default_layer = NULL, none_option = FALSE, none_label = "None", position = "top-right", panel_id = NULL, section_title = NULL, group_id = NULL )add_layer_selector_control( map, layer_ids, labels = NULL, default_layer = NULL, none_option = FALSE, none_label = "None", position = "top-right", panel_id = NULL, section_title = NULL, group_id = NULL )
map |
The map or map proxy object. |
layer_ids |
Vector of layer IDs to include in the selector. |
labels |
Named vector of labels for layers. If |
default_layer |
Default layer to select. If |
none_option |
Whether to include a "None" option that hides all layers. Default is |
none_label |
Label for the "None" option. Default is "None". |
position |
Position on the map if not using a control panel. Default is "top-right". |
panel_id |
ID of control panel to add to (optional). |
section_title |
Section title when added to a control panel. |
group_id |
ID of control group to add to (optional). |
The map or map proxy object for chaining.
# Load libraries library(spData) library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) nz_data <- spData::nz_height |> sf::st_transform(4326) map() |> add_circle_layer( id = "quakes", source = quakes_data ) |> add_circle_layer( id = "nz_elevation", source = nz_data ) |> add_layer_selector_control( layer_ids = c("quakes", "nz_elevation"), labels = c("quakes" = "Earthquakes", "nz_elevation" = "NZ Elevation") )# Load libraries library(spData) library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) nz_data <- spData::nz_height |> sf::st_transform(4326) map() |> add_circle_layer( id = "quakes", source = quakes_data ) |> add_circle_layer( id = "nz_elevation", source = nz_data ) |> add_layer_selector_control( layer_ids = c("quakes", "nz_elevation"), labels = c("quakes" = "Earthquakes", "nz_elevation" = "NZ Elevation") )
Add a line layer to a map or map proxy
add_line_layer( map, id, source, paint = NULL, layout = NULL, popup_column = NULL, hover_column = NULL, can_cluster = FALSE, under_id = NULL, filter = NULL, ... )add_line_layer( map, id, source, paint = NULL, layout = NULL, popup_column = NULL, hover_column = NULL, can_cluster = FALSE, under_id = NULL, filter = NULL, ... )
map |
The map object or map proxy to which the layer will be added. |
id |
A unique identifier for the layer. |
source |
The data source for the layer, if not a GeoJSON, it will be converted. |
paint |
A list of paint options for styling the layer. See |
layout |
A list of layout options for the layer. See |
popup_column |
The column name to use for popups. Default is |
hover_column |
The column name to use for hover effects. Default is |
can_cluster |
Whether the layer can be clustered. Default is |
under_id |
The ID of an layer already on the map to place this layer under.
Default is |
filter |
A filter expression to apply to the layer. Default is |
... |
Additional arguments to include in the layer definition.
|
The updated map object with the line layer added.
# Load libraries library(spData) library(sf) seine_data <- spData::seine |> sf::st_transform(4326) map() |> set_bounds(bounds = seine_data, padding = 100) |> add_line_layer( id = "seine_lines", source = seine_data, hover_column = "name" ) map() |> set_bounds(bounds = seine_data, padding = 100) |> add_line_layer( id = "seine_lines", source = seine_data, hover_column = "name", paint = get_paint_options( "line", options = list( colour = get_column_group( "name", c("Marne" = "#014f86", "Seine" = "#61a5c2"), "#a9d6e5" ), line_width = get_column_group("name", c("Seine" = 3), 1) ) ) )# Load libraries library(spData) library(sf) seine_data <- spData::seine |> sf::st_transform(4326) map() |> set_bounds(bounds = seine_data, padding = 100) |> add_line_layer( id = "seine_lines", source = seine_data, hover_column = "name" ) map() |> set_bounds(bounds = seine_data, padding = 100) |> add_line_layer( id = "seine_lines", source = seine_data, hover_column = "name", paint = get_paint_options( "line", options = list( colour = get_column_group( "name", c("Marne" = "#014f86", "Seine" = "#61a5c2"), "#a9d6e5" ), line_width = get_column_group("name", c("Seine" = 3), 1) ) ) )
A route is a line that can be animated along a set of points. This function adds a route to the map with a unique identifier and settings for the route's appearance and animation.
add_route(map, route_id, points, settings = list())add_route(map, route_id, points, settings = list())
map |
A toro map object or a map proxy object. |
route_id |
A unique identifier for the route. |
points |
A sf object containing the points of the route. |
settings |
A list of settings for the route (e.g., color, weight). |
The map or map proxy object for chaining.
if(interactive()){ library(shiny) library(toro) library(sf) line_data <- sf::st_sf( id = 1, geometry = sf::st_sfc( sf::st_linestring( cbind(c(172.2041, 163.9383), c(-32.56960, -46.43999)) ), crs = 4326 ) ) ui <- fluidPage( tagList( mapOutput("map"), actionButton("play_route", "Play Route Animation"), actionButton("pause_route", "Pause Route Animation"), actionButton("remove_route", "Remove Route") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_route(route_id = "route_line", points = line_data) }) observe({ req(input$map_loaded) mapProxy("map") |> play_route(route_id = "route_line") }) |> bindEvent(input$play_route) observe({ req(input$map_loaded) mapProxy("map") |> pause_route(route_id = "route_line") }) |> bindEvent(input$pause_route) observe({ req(input$map_loaded) mapProxy("map") |> remove_route(route_id = "route_line") }) |> bindEvent(input$remove_route) } }if(interactive()){ library(shiny) library(toro) library(sf) line_data <- sf::st_sf( id = 1, geometry = sf::st_sfc( sf::st_linestring( cbind(c(172.2041, 163.9383), c(-32.56960, -46.43999)) ), crs = 4326 ) ) ui <- fluidPage( tagList( mapOutput("map"), actionButton("play_route", "Play Route Animation"), actionButton("pause_route", "Pause Route Animation"), actionButton("remove_route", "Remove Route") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_route(route_id = "route_line", points = line_data) }) observe({ req(input$map_loaded) mapProxy("map") |> play_route(route_id = "route_line") }) |> bindEvent(input$play_route) observe({ req(input$map_loaded) mapProxy("map") |> pause_route(route_id = "route_line") }) |> bindEvent(input$pause_route) observe({ req(input$map_loaded) mapProxy("map") |> remove_route(route_id = "route_line") }) |> bindEvent(input$remove_route) } }
Add a source to the map
add_source(map, source_id, data, type = "geojson", cluster = FALSE, ...)add_source(map, source_id, data, type = "geojson", cluster = FALSE, ...)
map |
The map or map proxy object. |
source_id |
The ID for the source. |
data |
The data for the source, typically in GeoJSON format. |
type |
The type of the source. Default is |
cluster |
Whether to enable clustering for this source. Default is |
... |
Additional arguments to in pass directly to the JS addSource function. Documentation for this can be found on the MapLibre GL JS docs.
|
The map or map proxy object for chaining.
If you add a source directly in an add layer function, the source ID will
be automatically generated as source-{layer-id}.
# Load libraries library(sf) # Prepare data data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) # Display the source on map map() |> add_source( source_id = "my_source", data = sf::st_as_sf(quakes_data, coords = c("long", "lat"), crs = 4326) ) |> add_circle_layer(id = "quakes", source = "my_source")# Load libraries library(sf) # Prepare data data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) # Display the source on map map() |> add_source( source_id = "my_source", data = sf::st_as_sf(quakes_data, coords = c("long", "lat"), crs = 4326) ) |> add_circle_layer(id = "quakes", source = "my_source")
The speed control allows users to adjust the speed of an animation on the map, such as a time-based animation controlled by the timeline control. It can be added as a standalone control on the map or within a control panel for better organization of multiple controls.
add_speed_control( map, values = c(0.5, 1, 2), labels = c("Slow", "Normal", "Fast"), default_index = 2, position = "top-right", panel_id = NULL, section_title = NULL, group_id = NULL )add_speed_control( map, values = c(0.5, 1, 2), labels = c("Slow", "Normal", "Fast"), default_index = 2, position = "top-right", panel_id = NULL, section_title = NULL, group_id = NULL )
map |
The map or map proxy object. |
values |
Vector of speed multiplier values. Default is c(0.5, 1, 2). |
labels |
Vector of labels for each speed value. Default is c("Slow", "Normal", "Fast"). |
default_index |
Index of the default speed (1-based). Default is 2. |
position |
Position on the map if not using a control panel. Default is "top-right". |
panel_id |
ID of control panel to add to (optional). |
section_title |
Section title when added to a control panel. |
group_id |
Optional ID of the group to add the control to within a panel. |
The map or map proxy object for chaining.
# Add to a map (no dates specified) map() |> add_speed_control() # Change default options map() |> add_speed_control( values = c(0.5, 1, 2, 5), labels = c("Slow", "Normal", "Fast", "Super fast"), default_index = 4 # Start on Super fast ) # Add to a control panel map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_speed_control(panel_id = "my_panel") # Add to a control panel inside a control group map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_control_group( panel_id = "my_panel", group_id = "animation_controls", group_title = "Animation Controls" ) |> add_speed_control( panel_id = "my_panel", group_id = "animation_controls" )# Add to a map (no dates specified) map() |> add_speed_control() # Change default options map() |> add_speed_control( values = c(0.5, 1, 2, 5), labels = c("Slow", "Normal", "Fast", "Super fast"), default_index = 4 # Start on Super fast ) # Add to a control panel map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_speed_control(panel_id = "my_panel") # Add to a control panel inside a control group map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_control_group( panel_id = "my_panel", group_id = "animation_controls", group_title = "Animation Controls" ) |> add_speed_control( panel_id = "my_panel", group_id = "animation_controls" )
This layer is typically used for icons or pins.
add_symbol_layer( map, id, source, paint = NULL, layout = NULL, popup_column = NULL, hover_column = NULL, can_cluster = FALSE, under_id = NULL, filter = NULL, ... )add_symbol_layer( map, id, source, paint = NULL, layout = NULL, popup_column = NULL, hover_column = NULL, can_cluster = FALSE, under_id = NULL, filter = NULL, ... )
map |
The map object or map proxy to which the layer will be added. |
id |
A unique identifier for the layer. |
source |
The data source for the layer, if not a GeoJSON, it will be converted. |
paint |
A list of paint options for styling the layer. See |
layout |
A list of layout options for the layer. See |
popup_column |
The column name to use for popups. Default is |
hover_column |
The column name to use for hover effects. Default is |
can_cluster |
Whether the layer can be clustered. Default is |
under_id |
The ID of an layer already on the map to place this layer under.
Default is |
filter |
A filter expression to apply to the layer. Default is |
... |
Additional arguments to include in the layer definition.
|
The updated map object with the symbol layer added.
# Load libraries library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) # Create map and add fill layer map() |> add_symbol_layer( id = "test_layer", source = quakes_data )# Load libraries library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) # Create map and add fill layer map() |> add_symbol_layer( id = "test_layer", source = quakes_data )
This layer is typically used for text labels.
add_text_layer( map, id, source, paint = NULL, layout = NULL, popup_column = NULL, hover_column = NULL, can_cluster = FALSE, under_id = NULL, filter = NULL, ... )add_text_layer( map, id, source, paint = NULL, layout = NULL, popup_column = NULL, hover_column = NULL, can_cluster = FALSE, under_id = NULL, filter = NULL, ... )
map |
The map object or map proxy to which the layer will be added. |
id |
A unique identifier for the layer. |
source |
The data source for the layer, if not a GeoJSON, it will be converted. |
paint |
A list of paint options for styling the layer. See |
layout |
A list of layout options for the layer. See |
popup_column |
The column name to use for popups. Default is |
hover_column |
The column name to use for hover effects. Default is |
can_cluster |
Whether the layer can be clustered. Default is |
under_id |
The ID of an layer already on the map to place this layer under.
Default is |
filter |
A filter expression to apply to the layer. Default is |
... |
Additional arguments to include in the layer definition.
|
The updated map object with the text layer added.
# Load libraries library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) # Create map and add fill layer map() |> add_text_layer( id = "test_layer", source = quakes_data )# Load libraries library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) # Create map and add fill layer map() |> add_text_layer( id = "test_layer", source = quakes_data )
Add a tile selector control to the map or control panel
add_tile_selector_control( map, available_tiles = NULL, labels = NULL, default_tile = NULL, position = "top-right", panel_id = NULL, section_title = NULL, group_id = NULL )add_tile_selector_control( map, available_tiles = NULL, labels = NULL, default_tile = NULL, position = "top-right", panel_id = NULL, section_title = NULL, group_id = NULL )
map |
The map or map proxy object. |
available_tiles |
Vector of available tile options. If |
labels |
Named vector of labels for tiles. If |
default_tile |
Default tile to select. If |
position |
Position on the map if not using a control panel. Default is "top-right". |
panel_id |
ID of control panel to add to (optional). |
section_title |
Section title when added to a control panel. |
group_id |
ID of control group to add to (optional). |
The map or map proxy object for chaining.
# Add a tile selector that gives the ability to switch between all available tilesets all_tiles <- get_tile_options() map(loadedTiles = all_tiles) |> add_tile_selector_control(available_tiles = all_tiles)# Add a tile selector that gives the ability to switch between all available tilesets all_tiles <- get_tile_options() map(loadedTiles = all_tiles) |> add_tile_selector_control(available_tiles = all_tiles)
The timeline control allows for users to interact with a date-based timeline, and can be used to control an animation of map data over time.
add_timeline_control( map, start_date = NULL, end_date = NULL, position = "bottom-left", max_ticks = 3, panel_id = NULL, section_title = NULL, group_id = NULL )add_timeline_control( map, start_date = NULL, end_date = NULL, position = "bottom-left", max_ticks = 3, panel_id = NULL, section_title = NULL, group_id = NULL )
map |
The map or map proxy object. |
start_date |
Start date for the timeline (YYYY-MM-DD format). |
end_date |
End date for the timeline (YYYY-MM-DD format). |
position |
Position on the map if not using a control panel. Default is "bottom-left". |
max_ticks |
Maximum number of labeled ticks to prevent overlap. Default is 3. |
panel_id |
ID of control panel to add to (optional). |
section_title |
Section title when added to a control panel. |
group_id |
Optional ID of the group to add the control to within a panel. |
The map or map proxy object for chaining.
# Add to a map (no dates specified) map() |> add_timeline_control() # Add to map with dates map() |> add_timeline_control( start_date = Sys.Date(), end_date = Sys.Date() + 30 ) # Add to a control panel map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_timeline_control( start_date = Sys.Date(), end_date = Sys.Date() + 30, panel_id = "my_panel" ) # Add to a control panel inside a control group map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_control_group( panel_id = "my_panel", group_id = "animation_controls", group_title = "Animation Controls" ) |> add_timeline_control( start_date = Sys.Date(), end_date = Sys.Date() + 30, panel_id = "my_panel", group_id = "animation_controls" )# Add to a map (no dates specified) map() |> add_timeline_control() # Add to map with dates map() |> add_timeline_control( start_date = Sys.Date(), end_date = Sys.Date() + 30 ) # Add to a control panel map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_timeline_control( start_date = Sys.Date(), end_date = Sys.Date() + 30, panel_id = "my_panel" ) # Add to a control panel inside a control group map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_control_group( panel_id = "my_panel", group_id = "animation_controls", group_title = "Animation Controls" ) |> add_timeline_control( start_date = Sys.Date(), end_date = Sys.Date() + 30, panel_id = "my_panel", group_id = "animation_controls" )
Creates a toggle button that can show/hide a specific layer.
add_visibility_toggle( map, layer_id, control_id = NULL, left_label = "Toggle Layer", right_label = NULL, initial_state = TRUE, position = "top-right", panel_id = NULL, section_title = NULL, group_id = NULL )add_visibility_toggle( map, layer_id, control_id = NULL, left_label = "Toggle Layer", right_label = NULL, initial_state = TRUE, position = "top-right", panel_id = NULL, section_title = NULL, group_id = NULL )
map |
The map or map proxy object. |
layer_id |
ID of the layer to toggle visibility for. |
control_id |
ID for the control. If |
left_label |
Label text for the toggle button. Default is "Toggle Layer". |
right_label |
Label text for the toggle button when layer is hidden. Default is "Layer Hidden". |
initial_state |
Initial visibility state. Default is |
position |
Position on the map if not using a control panel. Default is "top-right". |
panel_id |
ID of control panel to add to (optional). |
section_title |
Section title when added to a control panel. |
group_id |
ID of control group to add to (optional). |
The map or map proxy object for chaining.
# Load libraries library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) map() |> add_circle_layer( id = "quakes", source = quakes_data ) |> add_visibility_toggle(layer_id = "quakes")# Load libraries library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) map() |> add_circle_layer( id = "quakes", source = quakes_data ) |> add_visibility_toggle(layer_id = "quakes")
Add a zoom control to the map
add_zoom_control( map, position = "top-right", control_options = list(), panel_id = NULL, section_title = NULL, group_id = NULL )add_zoom_control( map, position = "top-right", control_options = list(), panel_id = NULL, section_title = NULL, group_id = NULL )
map |
The map or map proxy object. |
position |
The position of the zoom control on the map. Default is |
control_options |
Additional options for the zoom control. Default is an empty list. |
panel_id |
ID of control panel to add to (optional). |
section_title |
Section title when added to a control panel. |
group_id |
Optional ID of the group to add the control to within a panel. |
The map proxy object for chaining.
See MapLibre NavigationControl docs for more information on available options.
add_zoom_control(map()) # Inside a control panel map() |> add_control_panel(panel_id = "my_panel", title = "View Controls") |> add_zoom_control(panel_id = "my_panel")add_zoom_control(map()) # Inside a control panel map() |> add_control_panel(panel_id = "my_panel", title = "View Controls") |> add_zoom_control(panel_id = "my_panel")
The ID of the shape is provided by the draw control when a shape is created.
delete_drawn_shape(proxy, shape_id)delete_drawn_shape(proxy, shape_id)
proxy |
The map proxy object created by |
shape_id |
The ID of the shape to delete. |
The map proxy object for chaining.
if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), selectInput("shape_ids", "Drawn shape IDs", choices = NULL), actionButton("remove_drawn_shape", "Remove drawn shape") ) ) server <- function(input, output, session) { drawn_shape_ids <- reactiveVal(character()) output$map <- renderMap({ map() |> add_draw_control() }) # Update the select input options with current shape IDs observe({ req(input$map_loaded) updateSelectInput(inputId = "shape_ids", choices = drawn_shape_ids()) }) # Update the list of drawn shape IDs when a new shape is created observe({ req(input$map_loaded, input$map_shape_created) new_shape <- get_drawn_shape(input$map_shape_created) drawn_shape_ids(c(drawn_shape_ids(), new_shape$id)) }) |> bindEvent(input$map_shape_created) # Delete the selected drawn shape when the button is clicked observe({ req(input$map_loaded, input$shape_ids) mapProxy("map") |> delete_drawn_shape(input$shape_ids) # Remove the deleted shape ID from the list of drawn shape IDs drawn_shape_ids(setdiff(drawn_shape_ids(), input$shape_ids)) }) |> bindEvent(input$remove_drawn_shape) } }if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), selectInput("shape_ids", "Drawn shape IDs", choices = NULL), actionButton("remove_drawn_shape", "Remove drawn shape") ) ) server <- function(input, output, session) { drawn_shape_ids <- reactiveVal(character()) output$map <- renderMap({ map() |> add_draw_control() }) # Update the select input options with current shape IDs observe({ req(input$map_loaded) updateSelectInput(inputId = "shape_ids", choices = drawn_shape_ids()) }) # Update the list of drawn shape IDs when a new shape is created observe({ req(input$map_loaded, input$map_shape_created) new_shape <- get_drawn_shape(input$map_shape_created) drawn_shape_ids(c(drawn_shape_ids(), new_shape$id)) }) |> bindEvent(input$map_shape_created) # Delete the selected drawn shape when the button is clicked observe({ req(input$map_loaded, input$shape_ids) mapProxy("map") |> delete_drawn_shape(input$shape_ids) # Remove the deleted shape ID from the list of drawn shape IDs drawn_shape_ids(setdiff(drawn_shape_ids(), input$shape_ids)) }) |> bindEvent(input$remove_drawn_shape) } }
This function exports a map widget as an image file using webshot2 or mapview. Works in non-Shiny contexts like RMarkdown, scripts, or interactive sessions.
export_map_image( map, filepath, width = 800, height = 600, delay = 2, zoom = 1, ... )export_map_image( map, filepath, width = 800, height = 600, delay = 2, zoom = 1, ... )
map |
A map object created by |
filepath |
The file path to save the image (including extension). |
width |
The width of the image in pixels. Default is 800. |
height |
The height of the image in pixels. Default is 600. |
delay |
The delay in seconds before capturing. Default is 2. |
zoom |
The zoom factor for the capture. Default is 1. |
... |
Additional arguments passed to |
The file path of the saved image (invisibly).
# Load library library(sf) data <- data.frame(lon = 174.8210, lat = -41.3096) |> sf::st_as_sf(coords = c("lon", "lat"), crs = 4326) # Create and export a map my_map <- map() |> add_circle_layer("epi_circle", source = data) export_map_image(my_map, file.path(tempdir(), "my_map.png"), width = 1200, height = 800)# Load library library(sf) data <- data.frame(lon = 174.8210, lat = -41.3096) |> sf::st_as_sf(coords = c("lon", "lat"), crs = 4326) # Create and export a map my_map <- map() |> add_circle_layer("epi_circle", source = data) export_map_image(my_map, file.path(tempdir(), "my_map.png"), width = 1200, height = 800)
The click input is a list containing the layerId, properties, geometry, and
time. Turn this into an sf object.
get_clicked_feature(clicked_feature_input)get_clicked_feature(clicked_feature_input)
clicked_feature_input |
A list representing the clicked feature. |
To get the clicked feature, use input$map_feature_click in a Shiny app, where map is the
ID of your map output. This input will contain a list representing the clicked feature whenever a
feature is clicked on the map. Pass this input to get_clicked_feature() to convert it into an
sf object for easier manipulation in R.
A sf object representing the clicked feature, or NULL.
time is not used in this function, but it is included in the input so that
the same feature can be clicked multiple times and the changed time means that the
input will be updated.
if(interactive()){ library(shiny) library(spData) library(sf) library(toro) nz_data <- spData::nz_height |> sf::st_transform(4326) ui <- fluidPage( tagList( mapOutput("map") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> set_bounds(bounds = nz_data) |> add_circle_layer( id = "nz_elevation", source = nz_data ) }) # Print the clicked feature as an sf object observe({ req(input$map_loaded, input$map_feature_click) print(get_clicked_feature(input$map_feature_click)) }) |> bindEvent(input$map_feature_click) } }if(interactive()){ library(shiny) library(spData) library(sf) library(toro) nz_data <- spData::nz_height |> sf::st_transform(4326) ui <- fluidPage( tagList( mapOutput("map") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> set_bounds(bounds = nz_data) |> add_circle_layer( id = "nz_elevation", source = nz_data ) }) # Print the clicked feature as an sf object observe({ req(input$map_loaded, input$map_feature_click) print(get_clicked_feature(input$map_feature_click)) }) |> bindEvent(input$map_feature_click) } }
Allows the column value to be used for styling features in a map layer.
get_column(column_name)get_column(column_name)
column_name |
String representing the name of the column to be used. |
List containing the paint or layout option to be set.
get_column("opacity") get_column("icon") # Use in a paint property: list("circle-color" = get_column("color"))get_column("opacity") get_column("icon") # Use in a paint property: list("circle-color" = get_column("color"))
Allows the data to be styled by the group option in the column.
get_column_boolean(column_name, true_value, false_value)get_column_boolean(column_name, true_value, false_value)
column_name |
String representing the name of the column to be used. |
true_value |
Value to use when the column value is |
false_value |
Value to use when the column value is |
List containing the paint or layout option to be set.
get_column_boolean("group", "red", "grey")get_column_boolean("group", "red", "grey")
Allows the data to be styled by the group option in the column.
get_column_group(column_name, named_group_values, default_value = "#cccccc")get_column_group(column_name, named_group_values, default_value = "#cccccc")
column_name |
String representing the name of the column to be used. |
named_group_values |
Vector of value strings named by the group values. The names of the vector should match the group values in the column. |
default_value |
String for the default value to use if no match is found. Default is "#cccccc". |
List containing the paint or layout option to be set.
If using numbers as the group values, then you need to use stats::setNames rather
than a named vector, as the names of the vector will be coerced to strings.
get_column_group("group", c("A" = "red", "B" = "blue"), "grey") get_column_group("opacity", stats::setNames(c(0.3, 0.5), c("A", "B")), 0.6)get_column_group("group", c("A" = "red", "B" = "blue"), "grey") get_column_group("opacity", stats::setNames(c(0.3, 0.5), c("A", "B")), 0.6)
Allows the data to be styled by the step breaks in the column.
get_column_steps(column_name, breaks, values)get_column_steps(column_name, breaks, values)
column_name |
String representing the name of the column to be used. |
breaks |
Numeric vector of thresholds (must be sorted ascending). |
values |
Vector of values, length = length(breaks) + 1. |
List containing the paint or layout option to be set.
get_column_steps("value", c(10, 20, 30), c("red", "orange", "yellow", "green"))get_column_steps("value", c(10, 20, 30), c("red", "orange", "yellow", "green"))
Parses the JSON string returned by the map widget when a shape is drawn.
Ensures that the ID of the shape is included in the resulting sf object.
get_drawn_shape(create_input_string)get_drawn_shape(create_input_string)
create_input_string |
A JSON string representing the drawn shape. |
To get the drawn shape, use input$map_shape_created in a Shiny app, where map is the ID of
your map output. This input will contain a JSON string representing the drawn shape whenever a
new shape is created using the draw control on the map. Pass this input to get_drawn_shape()
to convert it into an sf object for easier manipulation in R.
A sf object representing the drawn shape, or NULL.
if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_draw_control() }) # Update the list of drawn shape IDs when a new shape is created observe({ req(input$map_loaded, input$map_shape_created) new_shape <- get_drawn_shape(input$map_shape_created) print(new_shape) }) |> bindEvent(input$map_shape_created) } }if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_draw_control() }) # Update the list of drawn shape IDs when a new shape is created observe({ req(input$map_loaded, input$map_shape_created) new_shape <- get_drawn_shape(input$map_shape_created) print(new_shape) }) |> bindEvent(input$map_shape_created) } }
Parse a filter string into a list of filters that the map can use.
get_layer_filter(filter_str)get_layer_filter(filter_str)
filter_str |
A string or vector of strings representing the filter conditions. |
A list where the first element is "all" if multiple filters are provided, or a single filter condition.
# Filter to only show rows where the "layer_id" column is equal to "forests" get_layer_filter("layer_id == forests") # Filter to show rows where the "layer_id" column is equal to "sites" and the "project_status" # column is equal to "Confirmed" get_layer_filter(c("layer_id == sites", "project_status == Confirmed"))# Filter to only show rows where the "layer_id" column is equal to "forests" get_layer_filter("layer_id == forests") # Filter to show rows where the "layer_id" column is equal to "sites" and the "project_status" # column is equal to "Confirmed" get_layer_filter(c("layer_id == sites", "project_status == Confirmed"))
This function returns a list of layout options based on the layer type and any additional options provided.
get_layout_options(layer_type, options = list())get_layout_options(layer_type, options = list())
layer_type |
A string indicating the type of layer (e.g., "fill", "circle", "line"). |
options |
A list of additional options to customize the layout properties. See MapLibre docs for options.
|
A list of layout options suitable for the specified layer type.
You can provide any layout options found in the
MapLibre Layers docs in the options
argument, and they will be included in the returned list.
The default options are just a starting point and can be overridden by providing them in the
options argument.
get_column() for getting options from column values directly, get_column_group() for
getting options by spiliting column values into groups, and get_column_steps() for
getting options by spiliting column values into groups based on steps.
get_layout_options("line", list(line_cap = "butt", line_join = "bevel")) get_layout_options("symbol", list(icon_image = "yellow_pin", icon_size = 1.5)) # For horizontal flipping, provide left/right versions of your icon or use rotation fallback get_layout_options("symbol", list(icon_image = "arrow", icon_flip_horizontal = TRUE)) # Provide options outside of the defaults get_layout_options( "circle", list( "circle-sort-key" = get_column_steps( "elevation", c(3000), c(100, 200) ) ) )get_layout_options("line", list(line_cap = "butt", line_join = "bevel")) get_layout_options("symbol", list(icon_image = "yellow_pin", icon_size = 1.5)) # For horizontal flipping, provide left/right versions of your icon or use rotation fallback get_layout_options("symbol", list(icon_image = "arrow", icon_flip_horizontal = TRUE)) # Provide options outside of the defaults get_layout_options( "circle", list( "circle-sort-key" = get_column_steps( "elevation", c(3000), c(100, 200) ) ) )
This function returns a list of paint options based on the layer type and any additional options provided.
get_paint_options(layer_type, options = list())get_paint_options(layer_type, options = list())
layer_type |
A string indicating the type of layer (e.g., "fill", "circle", "line"). |
options |
A list of additional options to customize the paint properties. See MapLibre docs for full options.
|
A list of paint options suitable for the specified layer type.
You can provide any paint options found in the
MapLibre Layers docs in the options
argument, and they will be included in the returned list.
The default options are just a starting point and can be overridden by providing them in the
options argument.
get_column() for getting options from column values directly, get_column_group() for
getting options by spiliting column values into groups, and get_column_steps() for
getting options by spiliting column values into groups based on steps.
get_paint_options("line", list(colour = "blue", opacity = 0.8, line_width = 2)) get_paint_options("circle", list(colour = "red", circle_radius = 10, outline_colour = "black")) # Use with get_column for data-driven styling: get_paint_options("fill", list(colour = get_column("color"), opacity = get_column("opacity"))) get_paint_options("fill", list( colour = get_column_group("group", c("A" = "green", "B" = "blue")) )) get_paint_options("fill", list( opacity = get_column_steps("percent", c(25, 75), c("red", "orange", "yellow")) )) # Provide options outside of the defaults get_paint_options("circle", list("circle-blur" = 0.5))get_paint_options("line", list(colour = "blue", opacity = 0.8, line_width = 2)) get_paint_options("circle", list(colour = "red", circle_radius = 10, outline_colour = "black")) # Use with get_column for data-driven styling: get_paint_options("fill", list(colour = get_column("color"), opacity = get_column("opacity"))) get_paint_options("fill", list( colour = get_column_group("group", c("A" = "green", "B" = "blue")) )) get_paint_options("fill", list( opacity = get_column_steps("percent", c(25, 75), c("red", "orange", "yellow")) )) # Provide options outside of the defaults get_paint_options("circle", list("circle-blur" = 0.5))
Get available tile layer options
get_tile_options()get_tile_options()
A character vector of available tile layer options.
all_tiles <- get_tile_options()all_tiles <- get_tile_options()
Hide a layer from the map
hide_layer(proxy, layer_id)hide_layer(proxy, layer_id)
proxy |
The map proxy object created by |
layer_id |
The ID of the layer to hide. |
The map proxy object for chaining.
This does not remove the layer, it only hides it from view.
if(interactive()){ library(shiny) library(sf) library(toro) data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), actionButton("show_layer", "Show Layer"), actionButton("hide_layer", "Hide Layer") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_circle_layer( id = "quakes", source = quakes_data ) }) observe({ mapProxy("map") |> show_layer(layer_id = "quakes") }) |> bindEvent(input$show_layer) observe({ mapProxy("map") |> hide_layer(layer_id = "quakes") }) |> bindEvent(input$hide_layer) } }if(interactive()){ library(shiny) library(sf) library(toro) data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), actionButton("show_layer", "Show Layer"), actionButton("hide_layer", "Hide Layer") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_circle_layer( id = "quakes", source = quakes_data ) }) observe({ mapProxy("map") |> show_layer(layer_id = "quakes") }) |> bindEvent(input$show_layer) observe({ mapProxy("map") |> hide_layer(layer_id = "quakes") }) |> bindEvent(input$hide_layer) } }
This function creates a map htmlwidget for use in R and Shiny applications.
map( style = "lightgrey", center = c(174, -41), zoom = 2, width = "100%", height = NULL, session = shiny::getDefaultReactiveDomain(), ... )map( style = "lightgrey", center = c(174, -41), zoom = 2, width = "100%", height = NULL, session = shiny::getDefaultReactiveDomain(), ... )
style |
The style of the map. Default is "lightgrey". |
center |
The initial center of the map as a longitude/latitude pair. Default is c(174, -41). |
zoom |
The initial zoom level of the map. Default is 2. |
width |
The width of the widget. Optional. |
height |
The height of the widget. Optional. |
session |
The Shiny session object. Default is the current session. |
... |
Additional options to customize the map.
|
An object of class htmlwidget representing the map.
map() # Load two tilesets for the map to use map(loadedTiles = c("natgeo", "streets")) # Load two tilesets for the map to use and add maxzoom to satellite layer map(loadedTiles = list(natgeo = list(), satellite = list(maxZoom = 2)))map() # Load two tilesets for the map to use map(loadedTiles = c("natgeo", "streets")) # Load two tilesets for the map to use and add maxzoom to satellite layer map(loadedTiles = list(natgeo = list(), satellite = list(maxZoom = 2)))
Create a MapLibre GL output for use in Shiny
mapOutput(outputId, width = "100%", height = "600px")mapOutput(outputId, width = "100%", height = "600px")
outputId |
output variable to read from. |
width, height
|
Must be a valid CSS unit (like |
A MapLibre GL map for use in a Shiny UI.
if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() }) } }if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() }) } }
Create a proxy object for updating the map
mapProxy(outputId, session = shiny::getDefaultReactiveDomain())mapProxy(outputId, session = shiny::getDefaultReactiveDomain())
outputId |
The ID of the output element. |
session |
The Shiny session object (default is the current session). |
A proxy object for the map.
if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), checkboxInput("has_zoom_controls", "Remove Zoom Controls", value = TRUE) ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_zoom_control() }) observe({ req(input$map_loaded) if (input$has_zoom_controls == TRUE) { mapProxy("map") |> add_zoom_control() } else { mapProxy("map") |> remove_zoom_control() } }) |> bindEvent(input$has_zoom_controls) } }if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), checkboxInput("has_zoom_controls", "Remove Zoom Controls", value = TRUE) ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_zoom_control() }) observe({ req(input$map_loaded) if (input$has_zoom_controls == TRUE) { mapProxy("map") |> add_zoom_control() } else { mapProxy("map") |> remove_zoom_control() } }) |> bindEvent(input$has_zoom_controls) } }
Pause a route animation on a toro map
pause_route(map, route_id, settings = list())pause_route(map, route_id, settings = list())
map |
A toro map proxy object. |
route_id |
A unique identifier for the route. |
settings |
A list of settings for pausing the animation. |
The updated map proxy object.
if(interactive()){ library(shiny) library(toro) library(sf) line_data <- sf::st_sf( id = 1, geometry = sf::st_sfc( sf::st_linestring( cbind(c(172.2041, 163.9383), c(-32.56960, -46.43999)) ), crs = 4326 ) ) ui <- fluidPage( tagList( mapOutput("map"), actionButton("play_route", "Play Route Animation"), actionButton("pause_route", "Pause Route Animation"), actionButton("remove_route", "Remove Route") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_route(route_id = "route_line", points = line_data) }) observe({ req(input$map_loaded) mapProxy("map") |> play_route(route_id = "route_line") }) |> bindEvent(input$play_route) observe({ req(input$map_loaded) mapProxy("map") |> pause_route(route_id = "route_line") }) |> bindEvent(input$pause_route) observe({ req(input$map_loaded) mapProxy("map") |> remove_route(route_id = "route_line") }) |> bindEvent(input$remove_route) } }if(interactive()){ library(shiny) library(toro) library(sf) line_data <- sf::st_sf( id = 1, geometry = sf::st_sfc( sf::st_linestring( cbind(c(172.2041, 163.9383), c(-32.56960, -46.43999)) ), crs = 4326 ) ) ui <- fluidPage( tagList( mapOutput("map"), actionButton("play_route", "Play Route Animation"), actionButton("pause_route", "Pause Route Animation"), actionButton("remove_route", "Remove Route") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_route(route_id = "route_line", points = line_data) }) observe({ req(input$map_loaded) mapProxy("map") |> play_route(route_id = "route_line") }) |> bindEvent(input$play_route) observe({ req(input$map_loaded) mapProxy("map") |> pause_route(route_id = "route_line") }) |> bindEvent(input$pause_route) observe({ req(input$map_loaded) mapProxy("map") |> remove_route(route_id = "route_line") }) |> bindEvent(input$remove_route) } }
Play a route animation on a toro map
play_route(map, route_id, settings = list())play_route(map, route_id, settings = list())
map |
A toro map proxy object. |
route_id |
A unique identifier for the route. |
settings |
A list of settings for the animation (e.g., speed, loop). |
The updated map proxy object.
if(interactive()){ library(shiny) library(toro) library(sf) line_data <- sf::st_sf( id = 1, geometry = sf::st_sfc( sf::st_linestring( cbind(c(172.2041, 163.9383), c(-32.56960, -46.43999)) ), crs = 4326 ) ) ui <- fluidPage( tagList( mapOutput("map"), actionButton("play_route", "Play Route Animation"), actionButton("pause_route", "Pause Route Animation"), actionButton("remove_route", "Remove Route") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_route(route_id = "route_line", points = line_data) }) observe({ req(input$map_loaded) mapProxy("map") |> play_route(route_id = "route_line") }) |> bindEvent(input$play_route) observe({ req(input$map_loaded) mapProxy("map") |> pause_route(route_id = "route_line") }) |> bindEvent(input$pause_route) observe({ req(input$map_loaded) mapProxy("map") |> remove_route(route_id = "route_line") }) |> bindEvent(input$remove_route) } }if(interactive()){ library(shiny) library(toro) library(sf) line_data <- sf::st_sf( id = 1, geometry = sf::st_sfc( sf::st_linestring( cbind(c(172.2041, 163.9383), c(-32.56960, -46.43999)) ), crs = 4326 ) ) ui <- fluidPage( tagList( mapOutput("map"), actionButton("play_route", "Play Route Animation"), actionButton("pause_route", "Pause Route Animation"), actionButton("remove_route", "Remove Route") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_route(route_id = "route_line", points = line_data) }) observe({ req(input$map_loaded) mapProxy("map") |> play_route(route_id = "route_line") }) |> bindEvent(input$play_route) observe({ req(input$map_loaded) mapProxy("map") |> pause_route(route_id = "route_line") }) |> bindEvent(input$pause_route) observe({ req(input$map_loaded) mapProxy("map") |> remove_route(route_id = "route_line") }) |> bindEvent(input$remove_route) } }
Remove a cluster toggle control from the map
remove_cluster_toggle(proxy, layer_id, panel_id = NULL)remove_cluster_toggle(proxy, layer_id, panel_id = NULL)
proxy |
The map proxy object created by |
layer_id |
The ID of the layer whose cluster toggle control to remove. |
panel_id |
Optional. If provided, removes the control from the specified control panel. |
The map proxy object for chaining.
if(interactive()){ # Load libraries library(shiny) library(toro) library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), actionButton("remove_control", "Remove cluster control") ) ) server <- function(input, output, session) { output$map <- renderMap({ add_symbol_layer( id = "quakes", source = quakes_data, can_cluster = TRUE ) |> add_cluster_toggle(layer_id = "quakes") }) observe({ req(input$map_loaded) mapProxy("map") |> remove_cluster_toggle("quakes") }) |> bindEvent(input$remove_control) } }if(interactive()){ # Load libraries library(shiny) library(toro) library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), actionButton("remove_control", "Remove cluster control") ) ) server <- function(input, output, session) { output$map <- renderMap({ add_symbol_layer( id = "quakes", source = quakes_data, can_cluster = TRUE ) |> add_cluster_toggle(layer_id = "quakes") }) observe({ req(input$map_loaded) mapProxy("map") |> remove_cluster_toggle("quakes") }) |> bindEvent(input$remove_control) } }
Remove a control from the map
remove_control(proxy, control_id)remove_control(proxy, control_id)
proxy |
The map proxy object created by |
control_id |
The ID of the control to remove. |
The map proxy object for chaining.
if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), actionButton("remove_controls", "Remove controls") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_zoom_control() |> add_custom_control( id = "custom_control", html = "<p>I am a custom control</p>" ) }) observe({ req(input$map_loaded) mapProxy("map") |> remove_control("zoom_control") |> remove_control("custom_control") }) |> bindEvent(input$remove_controls) } }if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), actionButton("remove_controls", "Remove controls") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_zoom_control() |> add_custom_control( id = "custom_control", html = "<p>I am a custom control</p>" ) }) observe({ req(input$map_loaded) mapProxy("map") |> remove_control("zoom_control") |> remove_control("custom_control") }) |> bindEvent(input$remove_controls) } }
Remove a control group from a control panel
remove_control_group(proxy, panel_id, group_id)remove_control_group(proxy, panel_id, group_id)
proxy |
The map proxy object created by |
panel_id |
The ID of the control panel. |
group_id |
The ID of the control group to remove. |
The map proxy object for chaining.
if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), actionButton("remove_group1", "Remove control group 1") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_control_group( panel_id = "my_panel", group_id = "control_group1", group_title = "Control Group 1" ) |> add_control_group( panel_id = "my_panel", group_id = "control_group2", group_title = "Control Group 2" ) }) observe({ req(input$map_loaded) mapProxy("map") |> remove_control_group(panel_id = "my_panel", group_id = "control_group1") }) |> bindEvent(input$remove_group1) } }if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), actionButton("remove_group1", "Remove control group 1") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_control_group( panel_id = "my_panel", group_id = "control_group1", group_title = "Control Group 1" ) |> add_control_group( panel_id = "my_panel", group_id = "control_group2", group_title = "Control Group 2" ) }) observe({ req(input$map_loaded) mapProxy("map") |> remove_control_group(panel_id = "my_panel", group_id = "control_group1") }) |> bindEvent(input$remove_group1) } }
Remove the cursor coordinates control from the map
remove_cursor_coords_control(proxy, panel_id = NULL)remove_cursor_coords_control(proxy, panel_id = NULL)
proxy |
The map proxy object created by |
panel_id |
Optional. If provided, removes the cursor coordinates control
from the specified control panel. If |
The map proxy object for chaining.
if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( fluidRow( column(6, mapOutput("map_one")), column(6, mapOutput("map_two")) ), actionButton("remove_control", "Remove control") ) ) server <- function(input, output, session) { output$map_one <- renderMap({ map() |> add_cursor_coords_control() }) output$map_two <- renderMap({ map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_cursor_coords_control(panel_id = "my_panel") }) observe({ req(input$map_one_loaded, input$map_two_loaded) mapProxy("map_one") |> remove_cursor_coords_control() mapProxy("map_two") |> remove_cursor_coords_control(panel_id = "my_panel") }) |> bindEvent(input$remove_control) } }if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( fluidRow( column(6, mapOutput("map_one")), column(6, mapOutput("map_two")) ), actionButton("remove_control", "Remove control") ) ) server <- function(input, output, session) { output$map_one <- renderMap({ map() |> add_cursor_coords_control() }) output$map_two <- renderMap({ map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_cursor_coords_control(panel_id = "my_panel") }) observe({ req(input$map_one_loaded, input$map_two_loaded) mapProxy("map_one") |> remove_cursor_coords_control() mapProxy("map_two") |> remove_cursor_coords_control(panel_id = "my_panel") }) |> bindEvent(input$remove_control) } }
Remove a custom control from the map
remove_custom_control(proxy, control_id, panel_id = NULL)remove_custom_control(proxy, control_id, panel_id = NULL)
proxy |
The map proxy object created by |
control_id |
The ID of the custom control to remove. |
panel_id |
Optional. If provided, removes the control from the specified
control panel. If |
The map proxy object for chaining.
if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( fluidRow( column(6, mapOutput("map_one")), column(6, mapOutput("map_two")) ), actionButton("remove_control", "Remove control") ) ) server <- function(input, output, session) { output$map_one <- renderMap({ map() |> add_custom_control( id = "custom_control", html = "<p>I am a custom control</p>" ) }) output$map_two <- renderMap({ map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_custom_control( id = "custom_control", html = "<p>I am a custom control</p>", panel_id = "my_panel" ) }) observe({ req(input$map_one_loaded, input$map_two_loaded) mapProxy("map_one") |> remove_custom_control("custom_control") mapProxy("map_two") |> remove_custom_control("custom_control", panel_id = "my_panel") }) |> bindEvent(input$remove_control) } }if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( fluidRow( column(6, mapOutput("map_one")), column(6, mapOutput("map_two")) ), actionButton("remove_control", "Remove control") ) ) server <- function(input, output, session) { output$map_one <- renderMap({ map() |> add_custom_control( id = "custom_control", html = "<p>I am a custom control</p>" ) }) output$map_two <- renderMap({ map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_custom_control( id = "custom_control", html = "<p>I am a custom control</p>", panel_id = "my_panel" ) }) observe({ req(input$map_one_loaded, input$map_two_loaded) mapProxy("map_one") |> remove_custom_control("custom_control") mapProxy("map_two") |> remove_custom_control("custom_control", panel_id = "my_panel") }) |> bindEvent(input$remove_control) } }
Remove the draw control from the map
remove_draw_control(proxy, panel_id = NULL)remove_draw_control(proxy, panel_id = NULL)
proxy |
The map proxy object created by |
panel_id |
Optional. If provided, removes the draw control from the specified control panel. If NULL, removes the standalone draw control. |
The map proxy object for chaining.
if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), actionButton("remove_draw_control", "Remove draw control") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_draw_control() }) observe({ req(input$map_loaded) mapProxy("map") |> remove_draw_control() }) |> bindEvent(input$remove_draw_control) } }if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), actionButton("remove_draw_control", "Remove draw control") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_draw_control() }) observe({ req(input$map_loaded) mapProxy("map") |> remove_draw_control() }) |> bindEvent(input$remove_draw_control) } }
Remove the layer selector control from the map
remove_layer_selector_control(proxy, panel_id = NULL)remove_layer_selector_control(proxy, panel_id = NULL)
proxy |
The map proxy object created by |
panel_id |
Optional. If provided, removes the layer selector control from the specified
control panel. If |
The map proxy object for chaining.
if(interactive()){ # Load libraries library(shiny) library(toro) library(spData) library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) nz_data <- spData::nz_height |> sf::st_transform(4326) ui <- fluidPage( tagList( mapOutput("map"), actionButton("remove_control", "Remove layer selector control") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_circle_layer( id = "quakes", source = quakes_data ) |> add_circle_layer( id = "nz_elevation", source = nz_data ) |> add_layer_selector_control( layer_ids = c("quakes", "nz_elevation"), labels = c("quakes" = "Earthquakes", "nz_elevation" = "NZ Elevation") ) }) observe({ req(input$map_loaded) mapProxy("map") |> remove_layer_selector_control() }) |> bindEvent(input$remove_control) } }if(interactive()){ # Load libraries library(shiny) library(toro) library(spData) library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) nz_data <- spData::nz_height |> sf::st_transform(4326) ui <- fluidPage( tagList( mapOutput("map"), actionButton("remove_control", "Remove layer selector control") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_circle_layer( id = "quakes", source = quakes_data ) |> add_circle_layer( id = "nz_elevation", source = nz_data ) |> add_layer_selector_control( layer_ids = c("quakes", "nz_elevation"), labels = c("quakes" = "Earthquakes", "nz_elevation" = "NZ Elevation") ) }) observe({ req(input$map_loaded) mapProxy("map") |> remove_layer_selector_control() }) |> bindEvent(input$remove_control) } }
Remove an animation route from a toro map
remove_route(map, route_id, settings = list())remove_route(map, route_id, settings = list())
map |
A toro map proxy object. |
route_id |
A unique identifier for the route. |
settings |
A list of settings for removing the route. |
The updated map proxy object.
if(interactive()){ library(shiny) library(toro) library(sf) line_data <- sf::st_sf( id = 1, geometry = sf::st_sfc( sf::st_linestring( cbind(c(172.2041, 163.9383), c(-32.56960, -46.43999)) ), crs = 4326 ) ) ui <- fluidPage( tagList( mapOutput("map"), actionButton("play_route", "Play Route Animation"), actionButton("pause_route", "Pause Route Animation"), actionButton("remove_route", "Remove Route") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_route(route_id = "route_line", points = line_data) }) observe({ req(input$map_loaded) mapProxy("map") |> play_route(route_id = "route_line") }) |> bindEvent(input$play_route) observe({ req(input$map_loaded) mapProxy("map") |> pause_route(route_id = "route_line") }) |> bindEvent(input$pause_route) observe({ req(input$map_loaded) mapProxy("map") |> remove_route(route_id = "route_line") }) |> bindEvent(input$remove_route) } }if(interactive()){ library(shiny) library(toro) library(sf) line_data <- sf::st_sf( id = 1, geometry = sf::st_sfc( sf::st_linestring( cbind(c(172.2041, 163.9383), c(-32.56960, -46.43999)) ), crs = 4326 ) ) ui <- fluidPage( tagList( mapOutput("map"), actionButton("play_route", "Play Route Animation"), actionButton("pause_route", "Pause Route Animation"), actionButton("remove_route", "Remove Route") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_route(route_id = "route_line", points = line_data) }) observe({ req(input$map_loaded) mapProxy("map") |> play_route(route_id = "route_line") }) |> bindEvent(input$play_route) observe({ req(input$map_loaded) mapProxy("map") |> pause_route(route_id = "route_line") }) |> bindEvent(input$pause_route) observe({ req(input$map_loaded) mapProxy("map") |> remove_route(route_id = "route_line") }) |> bindEvent(input$remove_route) } }
Remove the speed control from the map
remove_speed_control(proxy, panel_id = NULL)remove_speed_control(proxy, panel_id = NULL)
proxy |
The map proxy object created by |
panel_id |
Optional. If provided, removes the speed control from the specified control panel. If NULL, removes the standalone speed control. |
The map proxy object for chaining.
# Add to a map map() |> add_speed_control() # Add to a control panel map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_speed_control(panel_id = "my_panel")# Add to a map map() |> add_speed_control() # Add to a control panel map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_speed_control(panel_id = "my_panel")
Remove the tile selector control from the map
remove_tile_selector_control(proxy, panel_id = NULL)remove_tile_selector_control(proxy, panel_id = NULL)
proxy |
The map proxy object created by |
panel_id |
Optional. If provided, removes the tile selector control from the specified
control panel. If |
The map proxy object for chaining.
if(interactive()){ # Load libraries library(shiny) library(toro) all_tiles <- get_tile_options() ui <- fluidPage( tagList( mapOutput("map"), actionButton("remove_control", "Remove tile selector control") ) ) server <- function(input, output, session) { output$map <- renderMap({ map(loadedTiles = all_tiles) |> add_tile_selector_control(available_tiles = all_tiles) }) observe({ req(input$map_loaded) mapProxy("map") |> remove_tile_selector_control() }) |> bindEvent(input$remove_control) } }if(interactive()){ # Load libraries library(shiny) library(toro) all_tiles <- get_tile_options() ui <- fluidPage( tagList( mapOutput("map"), actionButton("remove_control", "Remove tile selector control") ) ) server <- function(input, output, session) { output$map <- renderMap({ map(loadedTiles = all_tiles) |> add_tile_selector_control(available_tiles = all_tiles) }) observe({ req(input$map_loaded) mapProxy("map") |> remove_tile_selector_control() }) |> bindEvent(input$remove_control) } }
Remove the timeline control from the map
remove_timeline_control(proxy, panel_id = NULL)remove_timeline_control(proxy, panel_id = NULL)
proxy |
The map proxy object created by |
panel_id |
Optional. If provided, removes the timeline control from the specified control panel. If NULL, removes the standalone timeline control. |
The map proxy object for chaining.
# Add to a map map() |> add_timeline_control() # Add to a control panel map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_timeline_control(panel_id = "my_panel")# Add to a map map() |> add_timeline_control() # Add to a control panel map() |> add_control_panel(panel_id = "my_panel", title = "Map Settings") |> add_timeline_control(panel_id = "my_panel")
Remove a visibility toggle control from the map
remove_visibility_toggle(proxy, layer_id, panel_id = NULL)remove_visibility_toggle(proxy, layer_id, panel_id = NULL)
proxy |
The map proxy object created by |
layer_id |
The ID of the layer whose visibility toggle control to remove. |
panel_id |
Optional. If provided, removes the control from the specified control panel. |
The map proxy object for chaining.
if(interactive()){ # Load libraries library(shiny) library(toro) library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), actionButton("remove_control", "Remove visibility control") ) ) server <- function(input, output, session) { output$map <- renderMap({ add_circle_layer( id = "quakes", source = quakes_data ) |> add_visibility_toggle(layer_id = "quakes") }) observe({ req(input$map_loaded) mapProxy("map") |> remove_visibility_toggle("quakes") }) |> bindEvent(input$remove_control) } }if(interactive()){ # Load libraries library(shiny) library(toro) library(sf) # Prepare data data(quakes) quakes_data <- quakes |> sf::st_as_sf(coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), actionButton("remove_control", "Remove visibility control") ) ) server <- function(input, output, session) { output$map <- renderMap({ add_circle_layer( id = "quakes", source = quakes_data ) |> add_visibility_toggle(layer_id = "quakes") }) observe({ req(input$map_loaded) mapProxy("map") |> remove_visibility_toggle("quakes") }) |> bindEvent(input$remove_control) } }
Remove the zoom control from the map
remove_zoom_control(proxy, panel_id = NULL)remove_zoom_control(proxy, panel_id = NULL)
proxy |
The map proxy object created by |
panel_id |
Optional. If provided, removes the zoom control from the specified control panel.
If |
The map proxy object for chaining.
if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), checkboxInput("has_zoom_controls", "Remove Zoom Controls", value = TRUE) ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_zoom_control() }) observe({ req(input$map_loaded) if (input$has_zoom_controls == TRUE) { mapProxy("map") |> add_zoom_control() } else { mapProxy("map") |> remove_zoom_control() } }) |> bindEvent(input$has_zoom_controls) } }if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), checkboxInput("has_zoom_controls", "Remove Zoom Controls", value = TRUE) ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_zoom_control() }) observe({ req(input$map_loaded) if (input$has_zoom_controls == TRUE) { mapProxy("map") |> add_zoom_control() } else { mapProxy("map") |> remove_zoom_control() } }) |> bindEvent(input$has_zoom_controls) } }
Render a MapLibre GL map in Shiny
renderMap(expr, env = parent.frame(), quoted = FALSE)renderMap(expr, env = parent.frame(), quoted = FALSE)
expr |
An expression that generates a map. |
env |
The environment in which to evaluate |
quoted |
Is |
A rendered MapLibre GL map for use in a Shiny server.
if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() }) } }if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() }) } }
This function saves a map widget as a self-contained HTML file that can be opened in any web browser.
save_map_html(map, filepath, title = "Toro Map", selfcontained = TRUE, ...)save_map_html(map, filepath, title = "Toro Map", selfcontained = TRUE, ...)
map |
A map object created by |
filepath |
The file path to save the HTML file (should end with .html). |
title |
The title for the HTML page. Default is "Toro Map". |
selfcontained |
Whether to create a self-contained HTML file. Default is TRUE. |
... |
Additional arguments passed to |
The file path of the saved HTML file (invisibly).
# Load library library(sf) data <- data.frame(lon = 174.8210, lat = -41.3096) |> sf::st_as_sf(coords = c("lon", "lat"), crs = 4326) # Create and export a map my_map <- map() |> add_circle_layer("epi_circle", source = data) save_map_html(my_map, file.path(tempdir(), "my_map.html"))# Load library library(sf) data <- data.frame(lon = 174.8210, lat = -41.3096) |> sf::st_as_sf(coords = c("lon", "lat"), crs = 4326) # Create and export a map my_map <- map() |> add_circle_layer("epi_circle", source = data) save_map_html(my_map, file.path(tempdir(), "my_map.html"))
Set the map bounds
set_bounds(map, bounds, padding = 50, max_zoom = map$maxZoom)set_bounds(map, bounds, padding = 50, max_zoom = map$maxZoom)
map |
The map or map proxy object. |
bounds |
One of two formats:
|
padding |
The padding around the bounds in pixels. Default is 50. |
max_zoom |
The maximum zoom level to set. Default is the object's |
The map or map proxy object for chaining.
# Load libraries library(toro) library(spData) library(sf) nz_data <- spData::nz_height |> sf::st_transform(4326) map() |> set_bounds(list(list(-79, 43), list(-73, 45))) map() |> set_bounds(bounds = nz_data)# Load libraries library(toro) library(spData) library(sf) nz_data <- spData::nz_height |> sf::st_transform(4326) map() |> set_bounds(list(list(-79, 43), list(-73, 45))) map() |> set_bounds(bounds = nz_data)
Set a layout property for a layer on the map
set_layout_property(proxy, layer_id, property_name, value)set_layout_property(proxy, layer_id, property_name, value)
proxy |
The map proxy object created by |
layer_id |
The ID of the layer to update. |
property_name |
The name of the layout property to set. |
value |
The value to set for the layout property. |
The map proxy object for chaining.
if(interactive()){ library(shiny) library(sf) library(toro) data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), selectInput( "text_column", "Select Text Column", choices = c("depth", "mag", "stations") ) ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_text_layer( id = "quakes", source = quakes_data, layout = get_layout_options( "text", options = list( text_field = get_column("depth") ) ) ) }) observe({ req(input$map_loaded) mapProxy("map") |> set_layout_property( layer_id = "quakes", property_name = "text-field", value = get_column(input$text_column) ) }) |> bindEvent(input$text_column) } }if(interactive()){ library(shiny) library(sf) library(toro) data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), selectInput( "text_column", "Select Text Column", choices = c("depth", "mag", "stations") ) ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_text_layer( id = "quakes", source = quakes_data, layout = get_layout_options( "text", options = list( text_field = get_column("depth") ) ) ) }) observe({ req(input$map_loaded) mapProxy("map") |> set_layout_property( layer_id = "quakes", property_name = "text-field", value = get_column(input$text_column) ) }) |> bindEvent(input$text_column) } }
Set a paint property for a layer on the map
set_paint_property(proxy, layer_id, property_name, value)set_paint_property(proxy, layer_id, property_name, value)
proxy |
The map proxy object created by |
layer_id |
The ID of the layer to update. |
property_name |
The name of the paint property to set. |
value |
The value to set for the paint property. |
The map proxy object for chaining.
if(interactive()){ library(shiny) library(sf) library(toro) data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), selectInput( "colour", "Select Tile Layer", choices = c( "red", "orange", "yellow", "green", "blue", "indigo", "violet" ) ) ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_circle_layer(id = "quakes", source = quakes_data) }) observe({ req(input$map_loaded) mapProxy("map") |> set_paint_property( layer_id = "quakes", property_name = "circle-color", value = input$colour ) }) |> bindEvent(input$colour) } }if(interactive()){ library(shiny) library(sf) library(toro) data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), selectInput( "colour", "Select Tile Layer", choices = c( "red", "orange", "yellow", "green", "blue", "indigo", "violet" ) ) ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_circle_layer(id = "quakes", source = quakes_data) }) observe({ req(input$map_loaded) mapProxy("map") |> set_paint_property( layer_id = "quakes", property_name = "circle-color", value = input$colour ) }) |> bindEvent(input$colour) } }
Set data for a source on the map
set_source_data(proxy, source_id, data, type = "geojson")set_source_data(proxy, source_id, data, type = "geojson")
proxy |
The map proxy object created by |
source_id |
The ID of the source to update. |
data |
The data for the source, typically in GeoJSON format. |
type |
The type of the source. Default is |
The map proxy object for chaining.
if(interactive()){ library(shiny) library(sf) library(toro) data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), actionButton("btn", "Update Source Data") ) ) server <- function(input, output, session) { get_random_points <- function(data, n = 10) { random_rows <- runif(n, min = 1, max = nrow(data)) return(data[random_rows, ]) } output$map <- renderMap({ map() |> add_symbol_layer( id = "quakes", source = get_random_points(quakes_data) ) }) observe({ mapProxy("map") |> set_source_data( source_id = "source-quakes", data = get_random_points(quakes_data) ) }) |> bindEvent(input$btn) } }if(interactive()){ library(shiny) library(sf) library(toro) data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), actionButton("btn", "Update Source Data") ) ) server <- function(input, output, session) { get_random_points <- function(data, n = 10) { random_rows <- runif(n, min = 1, max = nrow(data)) return(data[random_rows, ]) } output$map <- renderMap({ map() |> add_symbol_layer( id = "quakes", source = get_random_points(quakes_data) ) }) observe({ mapProxy("map") |> set_source_data( source_id = "source-quakes", data = get_random_points(quakes_data) ) }) |> bindEvent(input$btn) } }
Set the tile layer for the map
set_tile_layer(map, tiles)set_tile_layer(map, tiles)
map |
The map or map proxy object. |
tiles |
A character vector of tile layer names.
Options include values returned from |
The map or map proxy object for chaining.
get_tile_options() for retrieving all tile options.
if(interactive()){ library(shiny) library(toro) all_tiles <- get_tile_options() ui <- fluidPage( tagList( mapOutput("map"), selectInput("tile_layer", "Select Tile Layer", choices = all_tiles) ) ) server <- function(input, output, session) { output$map <- renderMap({ map(loadedTiles = all_tiles) }) observe({ mapProxy("map") |> set_tile_layer(tiles = input$tile_layer) }) |> bindEvent(input$tile_layer) } }if(interactive()){ library(shiny) library(toro) all_tiles <- get_tile_options() ui <- fluidPage( tagList( mapOutput("map"), selectInput("tile_layer", "Select Tile Layer", choices = all_tiles) ) ) server <- function(input, output, session) { output$map <- renderMap({ map(loadedTiles = all_tiles) }) observe({ mapProxy("map") |> set_tile_layer(tiles = input$tile_layer) }) |> bindEvent(input$tile_layer) } }
Set the map zoom level
set_zoom(map, zoom)set_zoom(map, zoom)
map |
The map or map proxy object. |
zoom |
The zoom level to set. Default is 2. |
The map or map proxy object for chaining.
map() |> set_zoom(5)map() |> set_zoom(5)
Show a previously hidden layer on the map
show_layer(proxy, layer_id)show_layer(proxy, layer_id)
proxy |
The map proxy object created by |
layer_id |
The ID of the layer to show. |
The map proxy object for chaining.
if(interactive()){ library(shiny) library(sf) library(toro) data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), actionButton("show_layer", "Show Layer"), actionButton("hide_layer", "Hide Layer") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_circle_layer( id = "quakes", source = quakes_data ) }) observe({ mapProxy("map") |> show_layer(layer_id = "quakes") }) |> bindEvent(input$show_layer) observe({ mapProxy("map") |> hide_layer(layer_id = "quakes") }) |> bindEvent(input$hide_layer) } }if(interactive()){ library(shiny) library(sf) library(toro) data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), actionButton("show_layer", "Show Layer"), actionButton("hide_layer", "Hide Layer") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_circle_layer( id = "quakes", source = quakes_data ) }) observe({ mapProxy("map") |> show_layer(layer_id = "quakes") }) |> bindEvent(input$show_layer) observe({ mapProxy("map") |> hide_layer(layer_id = "quakes") }) |> bindEvent(input$hide_layer) } }
Toggle clustering for a layer on the map
toggle_clustering(proxy, layer_id, cluster = FALSE)toggle_clustering(proxy, layer_id, cluster = FALSE)
proxy |
The map proxy object created by |
layer_id |
The ID of the layer to toggle clustering for. |
cluster |
Whether to enable clustering. Default is |
The map proxy object for chaining.
if(interactive()){ library(shiny) library(sf) library(toro) data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), checkboxInput("toggle_cluster", "Toggle Clustering", value = TRUE) ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_symbol_layer( id = "quakes", source = quakes_data, can_cluster = TRUE ) }) observe({ mapProxy("map") |> toggle_clustering(layer_id = "quakes", cluster = input$toggle_cluster) }) |> bindEvent(input$toggle_cluster) } }if(interactive()){ library(shiny) library(sf) library(toro) data(quakes) quakes_data <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = 4326) ui <- fluidPage( tagList( mapOutput("map"), checkboxInput("toggle_cluster", "Toggle Clustering", value = TRUE) ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_symbol_layer( id = "quakes", source = quakes_data, can_cluster = TRUE ) }) observe({ mapProxy("map") |> toggle_clustering(layer_id = "quakes", cluster = input$toggle_cluster) }) |> bindEvent(input$toggle_cluster) } }
Toggle the visibility of a control on the map
toggle_control(proxy, control_id, show = TRUE)toggle_control(proxy, control_id, show = TRUE)
proxy |
The map proxy object created by |
control_id |
The ID of the control to toggle. |
show |
Logical indicating whether to show or hide the control. Default is |
The map proxy object for chaining.
if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), checkboxInput("show_controls", "Show controls", value = TRUE) ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_zoom_control() |> add_custom_control( id = "custom_control", html = "<p>I am a custom control</p>" ) }) observe({ req(input$map_loaded) mapProxy("map") |> toggle_control("zoom_control", show = input$show_controls) |> toggle_control("custom_control", show = input$show_controls) }) |> bindEvent(input$show_controls) } }if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), checkboxInput("show_controls", "Show controls", value = TRUE) ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_zoom_control() |> add_custom_control( id = "custom_control", html = "<p>I am a custom control</p>" ) }) observe({ req(input$map_loaded) mapProxy("map") |> toggle_control("zoom_control", show = input$show_controls) |> toggle_control("custom_control", show = input$show_controls) }) |> bindEvent(input$show_controls) } }
Show/hide the latitude and longitude grid on the map
toggle_lat_lng_grid(proxy, show = TRUE)toggle_lat_lng_grid(proxy, show = TRUE)
proxy |
The map proxy object created by |
show |
Logical indicating whether to show or hide the grid. Default is |
The map proxy object for chaining.
if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), actionButton("show_grid", "Show Grid"), actionButton("hide_grid", "Hide Grid") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_lat_lng_grid() }) observe({ mapProxy("map") |> toggle_lat_lng_grid(show = TRUE) }) |> bindEvent(input$show_grid) observe({ mapProxy("map") |> toggle_lat_lng_grid(show = FALSE) }) |> bindEvent(input$hide_grid) } }if(interactive()){ library(shiny) library(toro) ui <- fluidPage( tagList( mapOutput("map"), actionButton("show_grid", "Show Grid"), actionButton("hide_grid", "Hide Grid") ) ) server <- function(input, output, session) { output$map <- renderMap({ map() |> add_lat_lng_grid() }) observe({ mapProxy("map") |> toggle_lat_lng_grid(show = TRUE) }) |> bindEvent(input$show_grid) observe({ mapProxy("map") |> toggle_lat_lng_grid(show = FALSE) }) |> bindEvent(input$hide_grid) } }