8000 update news; keep improving docs · plotly/plotly.R@5e9db4b · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e9db4b

Browse files
committed
update news; keep improving docs
1 parent 7f519a9 commit 5e9db4b

File tree

3 files changed

+65
-11
lines changed

3 files changed

+65
-11
lines changed

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
* Upgraded to plotly.js v1.38.1. A _huge_ amount of features and improvements have been made since v1.29.2 (i.e., the version included in the last CRAN release of the R package - v4.7.1). Highlights include a complete re-write of `scattergl` to make it nearly feature complete with `scatter`, localization of text rendering (i.e., international translations), and two new trace types (`violin` & `table`). Read more about the v1.32.0 release [here](https://codeburst.io/notes-from-the-latest-plotly-js-release-b035a5b43e21) and the complete list of changes [here](https://github.com/plotly/plotly.js/releases).
66
* Support for **sf** (simple feature) data structures was added to `plot_ly()`, `plot_mapbox()`, and `plot_geo()` (via the new `add_sf()` function). See [this blog post](https://blog.cpsievert.me/2018/03/30/visualizing-geo-spatial-data-with-sf-and-plotly) for an overview.
77
* New "special arguments" `stroke`, `strokes`, `alpha_stroke`, `span`, and `spans` were added for easier control over the stroke (i.e., outline) appearance of various (filled) graphical marks. For an overview, see the **sf** blog post linked to in the bullet point above and the new package demos (list all demos with `demo(package = "plotly")`).
8-
* One may now inform `ggplotly()` about the relevant **shiny** output size via `session$clientData`. This ensures `ggplotly()` sizing is closer to **ggplot2** sizing, even on window resize. For an example, run `plotly_example("shiny", "ggplotly_sizing")`.
98
* The selection (i.e., linked-brushing) mode can now switch from 'transient' to 'persistent' by holding the 'shift' key. It's still possible to _force_ persistent selection by setting `persistent = TRUE` in `highlight()`, but `persistent = FALSE` (the default) is now recommended since it allows one to switch between [persistent/transient selection](https://plotly-book.cpsievert.me/linking-views-without-shiny.html#transient-versus-persistent-selection) in the browser, rather than at the command line.
9+
* The new `partial_bundle()` function makes it easy to leverage [partial bundles of plotly.js](https://github.com/plotly/plotly.js#partial-bundles) for reduced file sizes and faster render times.
10+
* One may now inform `ggplotly()` about the relevant **shiny** output size via `session$clientData`. This ensures `ggplotly()` sizing is closer to **ggplot2** sizing, even on window resize. For an example, run `plotly_example("shiny", "ggplotly_sizing")`.
1011
* Instead of an error, `ggplotly(NULL, "message")` and `plotly_build(NULL, "message")` now returns `htmltools::div("message")`, making it easier to relay messages in shiny when data isn't yet ready to plot (see #1116)
1112
* The `animation_button()` function gains a `label` argument, making it easier to control the label of an animation button generated through the `frame` API (see #1205).
1213

R/partial_bundles.R

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,59 @@
22
#'
33
#' Leveraging plotly.js' partial bundles can lead to smaller file sizes
44
#' and faster rendering. The full list of available bundles, and the
5-
#' trace types that they support, are available [here](https://github.com/plotly/plotly.js/blob/master/dist/README.md)
5+
#' trace types that they support, are available
6+
#' [here](https://github.com/plotly/plotly.js/blob/master/dist/README.md#partial-bundles)
7+
#'
8+
#' @details WARNING: use this function with caution when rendering multiple
9+
#' plotly graphs on a single website. That's because, if multiple plotly.js
10+
#' bundles are used, the most recent bundle will override the other bundles.
11+
#' See the examples section for an example.
612
#'
713
#' @param p a plotly object.
814
#' @param type name of the (partial) bundle. The default, `'auto'`, attempts to
9-
#' find the smallest single bundle that can render `p`. If no single partial bundle,
15+
#' find the smallest single bundle that can render `p`. If no single partial bundle
1016
#' can render `p`, then the full bundle is used.
1117
#' @param local whether or not to download the partial bundle so that it can be
1218
#' viewed later without an internet connection.
1319
#' @param minified whether or not to use a minified js file (non-minified file can be useful for debugging plotly.js)
1420
#' @author Carson Sievert
1521
#' @export
1622
#' @examples
23+
#'
24+
#' # ----------------------------------------------------------------------
25+
#' # This function is always safe to use when rendering a single
26+
#' # plotly graph. In this case, we get a 3x file reduction.
27+
#' # ----------------------------------------------------------------------
1728
#'
1829
#' library(plotly)
19-
#' p1 <- plot_ly(x = 1:10, y = 1:10) %>% add_markers()
20-
#' p2 <- partial_bundle(p1)
21-
#' f1 <- tempfile(fileext = ".html")
22-
#' f2 <- tempfile(fileext = ".html")
23-
#'
30+
#' p <- plot_ly(x = 1:10, y = 1:10) %>% add_markers()
2431
#' save_widget <- function(p, f) {
2532
#' owd <- setwd(dirname(f))
2633
#' on.exit(setwd(owd))
2734
#' htmlwidgets::saveWidget(p, f)
2835
#' mb <- round(file.info(f)$size / 1e6, 3)
2936
#' message("File is: ", mb," MB")
3037
#' }
31-
#' save_widget(p1, f1)
32-
#' save_widget(p2, f2)
38+
#' f1 <- tempfile(fileext = ".html")
39+
#' f2 <- tempfile(fileext = ".html")
40+
#' save_widget(p, f1)
41+
#' save_widget(partial_bundle(p), f2)
42+
#'
43+
#' # ----------------------------------------------------------------------
44+
#' # But, since plotly.js bundles override one another,
45+
#' # be careful when putting multiple graphs in a larger document!
46+
#' # Note how the surface (part of the gl3d bundle) renders, but the
47+
#' # heatmap (part of the cartesian bundle) doesn't...
48+
#' # ----------------------------------------------------------------------
49+
#'
50+
#' library(htmltools)
51+
#' p1 <- plot_ly(z = ~volcano) %>%
52+
#' add_heatmap() %>%
53+
#' partial_bundle()
54+
#' p2 <- plot_ly(z = ~volcano) %>%
55+
#' add_surface() %>%
56+
#' partial_bundle()
57+
#' browsable(tagList(p1, p2))
3358
#'
3459

3560

man/partial_bundle.Rd

Lines changed: 29 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0