Skip to content

Commit d7eaf38

Browse files
committed
add an explicit label argument to animation_button(), fixes #1205
1 parent 15b434e commit d7eaf38

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Upgraded to plotly.js v1.34.0. 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
* The selection 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.
77
* 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)
8+
* 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).
89

910
## CHANGES
1011

R/animate.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,16 @@ animation_slider <- function(p, hide = FALSE, ...) {
150150

151151

152152
#' @inheritParams animation_slider
153+
#' @param label a character string used for the animation button's label
153154
#' @export
154155
#' @rdname animation
155-
animation_button <- function(p, ...) {
156+
animation_button <- function(p, ..., label) {
156157

157158
p <- plotly_build(p)
158159
isAniButton <- vapply(p$x$layout$updatemenus, is_ani_button, logical(1))
160+
if (!missing(label)) {
161+
p$x$layout$updatemenus[[which(isAniButton)]]$buttons[[1]]$label <- label
162+
}
159163
p$x$layout$updatemenus[[which(isAniButton)]] <- modify_list(
160164
p$x$layout$updatemenus[[which(isAniButton)]], list(...)
161165
)

man/animation.Rd

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-animate-highlight.R

+12-1
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,15 @@ test_that("animation frames are boxed up correctly", {
315315

316316
})
317317

318-
318+
test_that("animation button can be customized", {
319+
320+
p <- plot_ly(mtcars, x = ~mpg, y = ~wt, frame = ~vs) %>%
321+
animation_button(label = "Custom", bgcolor = "red", font = list(color = "white"))
322+
323+
f <- plotly_build(p)$x
324+
325+
menu <- f$layout$updatemenus[[1]]
326+
expect_true(menu$bgcolor == "red")
327+
expect_true(menu$font$color == "white")
328+
expect_true(menu$buttons[[1]]$label == "Custom")
329+
})

0 commit comments

Comments
 (0)