Repository navigation
Plotly core render - #2503
Draft
msummersgill wants to merge 17 commits into
Draft
Plotly core render#2503msummersgill wants to merge 17 commits into
msummersgill wants to merge 17 commits into
Conversation
added 17 commits
November 13, 2026 14:10
plot_ly() objects are still built by plotly_build(); the result is then converted to a plotly.core figure (as_go_figure()), adding each trace with plotly.core's add_<type>() and the layout with update_layout(), and rendered with plotly.core's widget, which bundles plotly.js 4. - add_trace() and the add_*() functions plotly.core also has (add_pie(), add_histogram(), ...) are methods of plotly.core's generics; plotly.core's add_<type>() functions are re-exported and add lazy layers to plot_ly() objects. - Trace helpers without a plotly.js trace type (add_markers(), add_lines(), add_bars(), add_boxplot(), ...) are deprecated (once per session) and keep working as before. - Features plotly.js has removed are upgraded during the build: Mapbox traces/layout to MapLibre map ones, heatmapgl, legacy polar charts, title aliases, and trace transforms (applied in R). The build checks attributes against plotly.core's schema. - Shiny functions, save_image()/kaleido(), plotly_json(), last_plot() and TeX() come from plotly.core; orca(), export(), partial_bundle() and the Chart Studio functions are deprecated or defunct shims. - Removes the bundled plotly.js 2 (inst/htmlwidgets) and the code that only it and Chart Studio used.
- Removes verify_attr_names() and attrs_name_check(): plotly.core validates trace and layout attributes (names, nested attributes and values) when a plot is converted, so unknown attributes were reported twice. Unknown config() options, which only that check covered, are now dropped with a warning when the plot is rendered. - Removes the Chart Studio `apiSrc` tagging and the I() boxing of one-value data arrays from verify_attr(); plotly.core sends data arrays as arrays. Tests that checked the AsIs class now check the JSON plotly.js receives.
Removes R/shiny.R (shiny_defaults_set() and shiny_event_defaults()): plotly.core's widget, event_register() and event_unregister() already apply the same default events, so plotly_build() no longer fills them in. The test of the defaults checks the rendered widget.
partial_bundle() is re-exported from plotly.core, which ships plotly.js's partial bundles and picks the smallest one with the plot's trace types (it was a deprecated no-op); the bundle choice is carried over when a plot is converted to a plotly.core figure.
htmlwidgets collects a widget's dependencies before its preRenderHook runs, so those of the plotly.core widget a plot_ly() object is converted to in the hook were lost (plots rendered blank once plotly.core stopped listing plotly.js in its widget YAML; locales, MathJax and linked-highlighting libraries were already missing). - print(), knit_print() and htmltools::as.tags() of plot_ly() objects render plotly.core's widget (as_widget()), with all its dependencies. - For htmlwidgets::saveWidget(): plot_ly() widgets get plotly.js and crosstalk when created, config() adds locale and MathJax dependencies and highlight() selectize and colourpicker, as in plotly 4.x. - partial_bundle() for plot_ly() objects builds the plot and replaces its plotly.js dependency.
- traceify() computes each level's rows once (not once per column) and doesn't copy data when a level covers every row. - arrange_safe() sorts with radix order() and only reorders rows that aren't already in order; incomplete rows are removed only if there are any; the group index is only computed for traces drawn by group. - The build no longer calls vctrs, dplyr, tibble, rlang, tidyr or purrr: base helpers replace as_tibble(), arrange(), group_vars(), transpose(), eval_tidy(), is_na()/is_atomic() and (in fortify_sf()) left_join(); digest::digest() replaces rlang::hash() for selectize ids; the unused group_by() of segment data is dropped. About 2x faster on large plots (e.g. 0.70 s -> 0.30 s for three 1M-point WebGL traces); the JSON sent to plotly.js is unchanged.
… deprecated - plotly_build.go_figure() so subplot() can combine go_figure()s with plot_ly()/ggplotly() objects; no frames warning for empty frames - Drop the once-per-session deprecation of add_markers(), add_lines(), etc. - add_trace docs point to the plotly.core functions documenting every supported attribute
element_blank() text gave layout fonts size 0, which plotly.core's validators warn about (e.g. tickfont.size). Found by regression testing the plotly_book examples.
is_singular() gives the same result as length(uniq(x)) == 1 without unique.matrix(), which took 0.2 s for a 2000x2000 z.
Their deprecation/removal isn't part of the plotly.core backend and can be a separate change. Only what the backend needs is adapted: plotlyMainBundlePath() points to plotly.core's plotly.js and mathjax_path() is kept for orca().
plotly.core's save_image() now uses headless Chrome instead of the kaleido Python package. kaleido() is kept as a deprecated wrapper around plotly.core::chrome_exporter(). Visual tests use the Chrome exporter; reticulate is replaced by chromote in Suggests and the CI steps installing Python and kaleido are removed.
plotly.js widens one axis range to keep a map's aspect ratio, so ggplot2's graticule, which covers only the panel's ranges, stopped short of the plot area (more visibly with plotly.js 4, which no longer widens the margin for the last tick label). The graticule is now computed over a wider area with the same breaks and crs, and clipped to the plot area by plotly.js.
…dges" This reverts commit a6d1227.
plotly.core's highlight() takes the same options (and CSS colours from toRGB()); plotly_build() still completes them in supply_highlight_attrs().
pak takes a remote's package name from the GitHub repository name (plotly.R.core), so the plotly.core import wasn't resolved in CI.
plot_mapbox() traces are upgraded to scattermap, and the bounds to fit become the widget's fitBounds setting (p$x$fitBounds$map). MapLibre needs no Mapbox token, so these two tests no longer skip without one.
Contributor
Author
|
Visual snapshot difference summary attached for the 148 Visual test failures. Plot margins behavior for geo plots is slightly different in plotly.js latest and represents the closest thing to a true behavior change. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This is a early stage draft exploring a potential "plotly.core" backend based on msummersgill/plotly.R.core. plotly.core is still in an unstable development phase and has not yet been submitted to CRAN, so this PR is not a merge candidate.
Changes to
R/onplotly-core-rendercompared with plotly 4.12.1Comparison of branch
plotly-core-render(87fdb204) with upstream plotly 4.12.1 (4ff1c333).Overall: 21 files changed under
R/, +953 / −1,447 lines. Two files are new, four R files plusR/sysdata.rdaare removed, and fourteen are modified. A further 91 files underinst/htmlwidgetsare removed. Every previously exported function is still exported. Those whose code moved (plotlyOutput(),renderPlotly(),event_data(),plotlyProxy(),partial_bundle(),save_image(),TeX(),highlight(),last_plot(),plotly_json(),schema(), …) now come from plotly.core, imported inR/imports.R. Existing user code keeps the same function names.What changed, by file
New
R/go_figure.R(+415), the heart of the change.plot_ly()andggplotly()objects are still built byplotly_build().as_go_figure(), now exported, converts the result to a plotly.core figure, adding each trace with plotly.core'sadd_<type>()and the layout withupdate_layout(). That validates everything against the bundled plotly.js 4.3 schema, and invalid attributes are dropped with a warning. The file also contains:render_go_figure(),as_widget.plotly(), and print, knit andas.tagsmethods;partial_bundle.plotly();plotly_build.go_figure(), so plotly.core figures can go intosubplot();add_<type>.plotly()methods for every trace type plotly doesn't define itself;extract_keys());map,heatmapglbecomesheatmap, legacy polar becomesscatterpolar, and title aliases are rewritten.R/transforms.R(+220): plotly.js 2 removed tracetransforms(filter, groupby, sort, aggregate), so they are now applied in R before rendering. Plots using them keep working.Removed (moved to plotly.core)
R/shiny.R(−274) andR/proxy.R(−112): Shiny bindings, event registration andplotlyProxy().R/partial_bundles.R(−216): bundle selection. plotly.core ships the bundles, so plotly 4.x's download from cdn.plot.ly is gone.R/last_plot.R(−21).R/sysdata.rda: the stored plotly.js schema. It's now read lazily from plotly.core (R/onLoad.R,plotly_schema()).inst/htmlwidgets/(91 files): the widget JavaScript, plotly.js and its locales, MathJax 2, selectize, colourpicker and the typedarray/setPrototypeOf polyfills.Largely emptied
R/kaleido.R(−270):save_image()uses plotly.core's Chrome-based export;kaleido()remains as a deprecated wrapper.R/mathjax.R(−64):TeX()and the MathJax dependencies now come from plotly.core; a small local-MathJax helper stays fororca().R/highlight.R(−222):highlight()andattrs_selected()are re-exported from plotly.core. Onlyhighlight_defaults()remains, still used byplotly_build().R/dev.R(−26):plotly_json()now comes from plotly.core.Modified
R/plotly.R:as_widget()becomes an S3 generic (methodas_widget.list) creating theplotly_corewidget;plot_mapbox()no longer sets a Mapbox token (MapLibre maps don't need one).R/plotly_build.R:upgrade_removed();verify_attr_names(), the Shiny event defaults and the partial-bundle check, all now handled by plotly.core;columns_df(),data_groups(),transpose_list());unique()on large matrices (is_singular()) and needless list copies.R/utils.R: those base R helpers, a baseorder()in place ofdplyr::arrange(),digestin place ofrlang::hash, and removal of the old schema check.R/add.R: the docs now point to plotly.core's generated documentation of every trace attribute.R/layout.R:config()becomes a method,config.plotly();rangeslider()only sets a range when both ends are given.R/subplots.R:mapboxbecomesmap, and plotly.core figures are accepted as input.R/ggplotly.R: two attribute fixes found by the new validation:yanchor = "center"becomes"middle", andlinetypebecomesdash.R/sf.R: a base R join replacesdplyr::left_join.R/imports.R: imports plotly.core (exceptschema) and re-exports its functions.ggplot2is imported withoutlast_plotandset_last_plot.DESCRIPTION:Remotes);promisesis dropped from Imports;reticulateis replaced bychromotein Suggests.Why things moved to plotly.core
plot_ly(),ggplotly(),go_figure()orpx_*(). That covers the widget JavaScript, plotly.js, Shiny events and proxies, partial bundles, static export, MathJax and crosstalk highlighting. Keeping them in the shared lower layer means one widget and one copy of plotly.js, and fixes like typed arrays, crosstalk and proxy streaming reach all four interfaces at once. Two widgets would drift apart.verify_attr_names()and stored schema, and catch real bugs: the twoggplotly()fixes above came from this.go_figure.Randtransforms.Rtranslate features plotly.js has since removed (Mapbox, heatmapgl, legacy polar, transforms, title aliases), so existing plots keep working on the new renderer.save_image()uses plotly.core's Chrome-based export, which sets itself up from R, in place of Kaleido through reticulate.kaleido()stays as a deprecated wrapper.plotly_build(), account for the gains measured in the render-performance vignette.What stays in plotly is the R-specific layer:
plot_ly()and its data-mapping grammar,ggplotly(),subplot(),layout(),style(),highlight_key(), animation helpers andplotly_build(). plotly.core is plotly.py's equivalent, and plotly is the R grammar on top of it.