Skip to contents

The mosaicr package integrates R with the Mosaic data visualization framework from UW Data, enabling scalable and interactive data visualization in R applications and documents.

What is Mosaic?

Mosaic is a framework for linking databases and interactive views that enables:

  • Scalable visualizations that handle millions of data points efficiently
  • Interactive dashboards with client-side interactions
  • Database integration with optimized query processing
  • Grammar of graphics approach to visualization specification

Installation

You can install the development version of mosaicr from GitHub with:

# install.packages("pak")
pak::pkg_install("dfalbel/mosaicr")

Quick Start

Static Documents

For R Markdown documents or standalone HTML widgets:

library(mosaicr)

# Create a scatter plot specification
spec <- list(
  plot = list(
    mark = "dot",
    data = list(from = "cars"),
    x = "speed",
    y = "dist"
  )
)

# Generate the visualization
mosaic(spec, cars = cars)

Shiny Applications

For interactive Shiny apps with server-side data processing:

library(shiny)
library(mosaicr)
library(DBI)

ui <- fluidPage(
  mosaicOutput("plot")
)

server <- function(input, output, session) {
  # Connect to database
  con <- dbConnect(duckdb::duckdb(), ":memory:")
  dbWriteTable(con, "mtcars", mtcars)

  # Register mosaic server
  api_id <- mosaicServer("mosaic_api", con)

  # Create plot
  output$plot <- renderMosaic({
    mosaic(
      api = api_id(),
      spec = list(
        plot = list(
          mark = "dot",
          data = list(from = "mtcars"),
          x = "mpg",
          y = "disp"
        )
      )
    )
  })
}

shinyApp(ui, server)

Key Features

  • HTML Widget Integration: Works in R Markdown, Jupyter notebooks, and standalone HTML
  • Shiny Support: Full integration with Shiny applications
  • Database Backend: Efficient data processing with DuckDB
  • Arrow Format: Optimized data transfer using Apache Arrow

TODO:

  • Interactions: Support for interactors such as zoom, pan, and selection
  • Linked Views: Coordinated multiple views for complex dashboards

Examples and Documentation

For complete examples, tutorials, and API documentation, visit the package website:

🌐 https://dfalbel.github.io/mosaicr/

License

MIT © Daniel Falbel