Learn R Programming

aisdk (version 1.1.0)

ggplot_to_frontend_json: Export ggplot as Frontend-Ready JSON

Description

Exports a ggplot object as JSON optimized for frontend rendering. Addresses all frontend feedback:

  • Strict scalar typing (no for missing values)

  • Structured units with pre-calculated pixel values

  • Stable IDs for React keys

  • Consistent Array of Structures pattern

Usage

ggplot_to_frontend_json(
  plot,
  width = 800,
  height = 600,
  include_data = TRUE,
  include_built = FALSE,
  pretty = FALSE
)

Value

JSON string optimized for frontend.

Arguments

plot

A ggplot object.

width

Plot width in pixels.

height

Plot height in pixels.

include_data

Whether to include data.

include_built

Whether to include ggplot_build() output.

pretty

Format JSON with indentation.

Examples

Run this code
# \donttest{
if (interactive()) {
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
json <- ggplot_to_frontend_json(p, width = 800, height = 600)
}
# }

Run the code above in your browser using DataLab