Launches a lightweight Shiny application to interactively visualize routing
on a local OSRM server. This interface mimics the r5rgui experience,
supporting left-click for start, right-click for end, and draggable markers.
Usage
osrm_gui(
input_osrm = NULL,
port = "auto",
style = "https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json",
center = NULL,
zoom = NULL,
autozoom = TRUE,
update_while_drag = FALSE,
debug = FALSE
)Arguments
- input_osrm
Optional. Can be:
An OSRM job process (an
osrm_serverobject inheriting fromprocessx::process) returned byosrm_start()orosrm_start_server(). When providing a process, you must also specifyportexplicitly.A path string to an
.osrm.hsgror.osrm.mldgrfile.A path string to an
.osm.pbffile (will be prepared and started).NULL(default): Auto-detects a running OSRM server usingosrm_servers(). Errors if no servers are running.
- port
Integer or
"auto". The port the server is running on (or should run on). Defaults to"auto", which attempts to auto-detect a running OSRM server usingosrm_servers(). If multiple servers are running, the most recent one is selected with a warning. If no servers are running, an error is raised.- style
Character. Map style for
mapgl. Defaults to "https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json".- center
Numeric vector of length 2 (
c(lng, lat)), or named list (list(lng = ..., lat = ...)), orNULL(default). Initial map center. IfNULLandinput_osrmis a.osm.pbffile, attempts to auto-center on the PBF extent. Priority is given to a fast pure R header parser andosmium fileinfo(fast); otherwise estimates the extent by sampling a small number of features viasf::st_read()(for example, reading with aLIMIT 10query).- zoom
Numeric. Initial zoom level. If
NULL(default) and center is auto-detected from PBF, defaults to 9. Otherwise uses map default.- autozoom
Logical. Whether to enable auto-zoom by default. Defaults to
TRUE.- update_while_drag
Logical. Whether to enable live tracking mode by default (updates route while dragging). Defaults to
FALSE.- debug
Logical. Whether to enable debug mode (prints OSRM requests to console). Defaults to
FALSE.
Details
The function checks for optional dependencies shiny, mapgl, osrm, sf, and DT.
If missing, it prompts the user to install them.
It attempts to detect an active OSRM server. If an OSRM job process (from
osrm_start()) is passed, it uses that configuration. If a path is passed,
it will start a temporary server for the session.
Examples
if (interactive()) {
# 1. Auto-detect running server (errors if none running):
osrm_gui()
# 2. Connect to specific port:
# osrm_gui(port = 5001)
# 3. Start from a graph file (auto-center on PBF):
# osrm_gui("berlin.osrm.mldgr")
# 4. Start from PBF with auto-center:
# osrm_gui("berlin.osm.pbf")
# 5. Explicit center and zoom:
# osrm_gui(port = 5001, center = c(13.4, 52.5), zoom = 12)
# 6. Use an existing process (must specify port):
# srv <- osrm_start("graph.osrm.mldgr", port = 6000)
# osrm_gui(srv, port = 6000)
# 7. Enable debug mode:
# osrm_gui(debug = TRUE)
}