This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
plotly is an R package for creating interactive web graphics via the plotly.js JavaScript library. It provides two main interfaces:
ggplotly(): Converts ggplot2 objects to interactive plotly visualizationsplot_ly(): Direct interface to plotly.js for specialized chart types
# Run all tests
devtools::test()
# Run visual tests (requires kaleido via reticulate)
Sys.setenv("VISUAL_TESTS" = "true")
devtools::test()
# Run a single test file
devtools::test(filter = "ggplot-bar")rcmdcheck::rcmdcheck()devtools::document()For consistent visual test results:
docker run -v $(pwd):/home/plotly --privileged -p 3838:3838 cpsievert/plotly-orcaAccess the validation Shiny app at http://0.0.0.0:3838
CI-only visual test run:
docker run -e VMODE="ci" -v $(pwd):/home/plotly --privileged cpsievert/plotly-orcaThe conversion from ggplot2 to plotly follows this flow:
ggplotly()(R/ggplotly.R): Entry point that dispatches on input typegg2list()(R/ggplotly.R): Main conversion function that:- Builds the ggplot object to extract computed data
- Processes each layer through
layers2traces() - Processes layout through
layers2layout()
layers2traces()(R/layers2traces.R): Converts ggplot2 geom layers to plotly trace objectslayers2layout()(R/layers2layout.R): Converts ggplot2 theme/coordinate settings to plotly layout
plot_ly()(R/plotly.R): Creates a plotly object with trace attributesadd_trace()andadd_*()functions (R/add.R): Add traces to existing plotslayout()(R/layout.R): Modify plot layoutplotly_build()(R/plotly_build.R): Evaluates lazy attributes and creates final JSON for plotly.js
R/shiny.R: Shiny integration and event handlingR/subplots.R: Combining multiple plotsR/highlight.R: Linked brushing/crosstalk supportR/animate.R: Animation supportR/kaleido.R,R/orca.R: Static image export
Tests should check the return value of plotly_build():
test_that("example test", {
p <- plot_ly(x = 1:10, y = 1:10)
built <- plotly_build(p)
expect_equal(built$x$data[[1]]$x, 1:10)
})Visual tests use expect_doppelganger() from tests/testthat/helper-vdiffr.R:
test_that("visual test", {
p <- plot_ly(x = 1:10, y = 1:10)
expect_doppelganger(p, "scatter-basic")
})Follow the tidyverse style guide: http://style.tidyverse.org/