| Title: | R Bindings to 'Deck.gl' |
|---|---|
| Description: | Provides R bindings for 'deck.gl', a 'WebGL' framework for rendering large interactive spatial and tabular visualizations. The package supplies 'htmlwidgets' and 'shiny' bindings, supports 'DuckDB'-backed data hydration, and bundles the JavaScript assets needed to render 'deck.gl' specifications from R. |
| Authors: | Timur Rizvanov [aut, cre], Edward C. Ruiz [aut], Ruben Dries [aut, rev], Dries Lab [fnd] (Host laboratory and funding source), Boston University [fnd] (Undergraduate Research Opportunities Program (UROP)) |
| Maintainer: | Timur Rizvanov <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-06-02 08:59:46 UTC |
| Source: | https://github.com/tirizvanov/rdeckgl |
Creates an interactive deck.gl visualization from a JSON or YAML specification. Supports server-side data hydration via DuckDB for efficient data handling.
deckgl( spec, specType = c("auto", "json", "yaml"), data = NULL, con = NULL, data_transport = c("auto", "file", "inline"), data_dir = NULL, width = NULL, height = NULL )deckgl( spec, specType = c("auto", "json", "yaml"), data = NULL, con = NULL, data_transport = c("auto", "file", "inline"), data_dir = NULL, width = NULL, height = NULL )
spec |
Deck.gl specification as an R list, JSON text, JSON file path, YAML text, or YAML file path. |
specType |
One of "auto" (default), "json", or "yaml". Auto-detection attempts to infer the format from the input. |
data |
Named list of data.frames to register in DuckDB. These tables can be referenced in the spec using 'type = "duckdb"' data nodes. |
con |
Optional DuckDB connection to use for queries. If provided, this connection will be used instead of creating a new one. This is useful for GeoArrow workflows where you need spatial extension and geometry tables already set up. |
data_transport |
How hydrated Arrow/Parquet query results are delivered to the browser. '"auto"' uses '"file"' when 'data_dir' is supplied and otherwise falls back to '"inline"' for portable widgets; '"inline"' embeds base64 payloads in the widget; '"file"' writes binary files to 'data_dir' and uses relative URLs. |
data_dir |
Directory for '"file"' transport. Serve or save the widget from the same directory so relative URLs resolve. |
width |
CSS or pixel width (e.g. "100%", "600px", or numeric). |
height |
CSS or pixel height (e.g. "100%", "600px", or numeric). |
An htmlwidget that renders the Deck.gl visualization.
if (interactive()) { # Simple scatterplot with inline data spec <- list( `@type` = "DeckGL", initialViewState = list( longitude = -122.4, latitude = 37.76, zoom = 12, pitch = 0, bearing = 0 ), layers = list( list( `@type` = "ScatterplotLayer", id = "scatterplot", data = list( type = "duckdb", query = "SELECT lon, lat, radius FROM points" ), getPosition = "@=[lon, lat]", getRadius = "@=radius", getFillColor = c(255, 0, 0) ) ) ) data <- list( points = data.frame( lon = c(-122.4, -122.45, -122.35), lat = c(37.76, 37.78, 37.74), radius = c(100, 150, 200) ) ) deckgl(spec = spec, data = data) }if (interactive()) { # Simple scatterplot with inline data spec <- list( `@type` = "DeckGL", initialViewState = list( longitude = -122.4, latitude = 37.76, zoom = 12, pitch = 0, bearing = 0 ), layers = list( list( `@type` = "ScatterplotLayer", id = "scatterplot", data = list( type = "duckdb", query = "SELECT lon, lat, radius FROM points" ), getPosition = "@=[lon, lat]", getRadius = "@=radius", getFillColor = c(255, 0, 0) ) ) ) data <- list( points = data.frame( lon = c(-122.4, -122.45, -122.35), lat = c(37.76, 37.78, 37.74), radius = c(100, 150, 200) ) ) deckgl(spec = spec, data = data) }
Use this in the UI to create a placeholder for the Deck.gl visualization.
deckglOutput(outputId, width = "100%", height = "400px")deckglOutput(outputId, width = "100%", height = "400px")
outputId |
output variable name |
width, height
|
CSS dimensions (e.g. '100%', '400px') for the container. |
A Shiny output binding for use in the UI.
if (interactive()) { library(shiny) library(rDeckgl) ui <- fluidPage( deckglOutput("myDeckgl", height = "600px") ) server <- function(input, output, session) { output$myDeckgl <- renderDeckgl({ deckgl(spec = my_spec, data = my_data) }) } shinyApp(ui, server) }if (interactive()) { library(shiny) library(rDeckgl) ui <- fluidPage( deckglOutput("myDeckgl", height = "600px") ) server <- function(input, output, session) { output$myDeckgl <- renderDeckgl({ deckgl(spec = my_spec, data = my_data) }) } shinyApp(ui, server) }
'ggsql()' lets you describe a Deck.gl visualization using the ggsql dialect (VISUALIZE / DRAW / PLACE / SCALE / LABEL / SETTING) instead of the native Deck.gl spec. The parser is shared with rMosaic; this entry point compiles for the Deck.gl rendering path, which is the right choice for spatial layers (polygons, hex grids, big point clouds, GeoArrow data).
ggsql(sql, data = NULL, con = NULL, width = NULL, height = NULL, ...)ggsql(sql, data = NULL, con = NULL, width = NULL, height = NULL, ...)
sql |
A character scalar containing ggsql. |
data |
Optional named list of data.frames to register in the widget's DuckDB before rendering. Use this when the FROM source in the SQL is not already a table the widget's DuckDB can see. |
con |
Optional DuckDB connection. If supplied it is reused instead of a fresh one (mirrors the 'deckgl()' argument). Useful for GiottoDB / dbProject workflows. |
width, height
|
Optional widget dimensions. |
... |
Reserved for forward compatibility. |
An htmlwidget produced by [deckgl()].
[deckgl()].
Use this in the server to render the Deck.gl visualization to the output.
renderDeckgl(expr, env = parent.frame(), quoted = FALSE)renderDeckgl(expr, env = parent.frame(), quoted = FALSE)
expr |
An expression that generates a call to |
env |
The environment in which to evaluate |
quoted |
Is |
A Shiny render function for use in the server.
if (interactive()) { library(shiny) library(rDeckgl) ui <- fluidPage( deckglOutput("myDeckgl") ) server <- function(input, output, session) { output$myDeckgl <- renderDeckgl({ spec <- list( `@type` = "DeckGL", initialViewState = list(longitude = -122.4, latitude = 37.76, zoom = 12), layers = list( list( `@type` = "ScatterplotLayer", id = "points", data = list(type = "duckdb", query = "SELECT * FROM points"), getPosition = "@=[lon, lat]", getRadius = 100, getFillColor = c(255, 0, 0) ) ) ) deckgl(spec = spec, data = list(points = data.frame(lon = -122.4, lat = 37.76))) }) } shinyApp(ui, server) }if (interactive()) { library(shiny) library(rDeckgl) ui <- fluidPage( deckglOutput("myDeckgl") ) server <- function(input, output, session) { output$myDeckgl <- renderDeckgl({ spec <- list( `@type` = "DeckGL", initialViewState = list(longitude = -122.4, latitude = 37.76, zoom = 12), layers = list( list( `@type` = "ScatterplotLayer", id = "points", data = list(type = "duckdb", query = "SELECT * FROM points"), getPosition = "@=[lon, lat]", getRadius = 100, getFillColor = c(255, 0, 0) ) ) ) deckgl(spec = spec, data = list(points = data.frame(lon = -122.4, lat = 37.76))) }) } shinyApp(ui, server) }