Skip to content

Commit 4c19ad4

Browse files
committed
Add rangeslider() function
1 parent d723b1a commit 4c19ad4

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export(plotly_build)
119119
export(plotly_data)
120120
export(plotly_empty)
121121
export(plotly_json)
122+
export(rangeslider)
122123
export(rename)
123124
export(rename_)
124125
export(renderPlotly)

R/layout.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,27 @@ layout.plotly <- function(p, ..., data = NULL) {
3030
p
3131
}
3232

33+
#' Add a range slider to the x-axis
34+
#'
35+
#' @param a plotly object.
36+
#' @param ... these arguments are documented here
37+
#' \url{https://plot.ly/r/reference/#layout-xaxis-rangeslider}
38+
#' @export
39+
#' @author Carson Sievert
40+
#' @examples
41+
#'
42+
#' plot_ly(x = time(USAccDeaths), y = USAccDeaths) %>%
43+
#' add_lines() %>%
44+
#' rangeslider()
45+
#'
46+
rangeslider <- function(p, ...) {
47+
if (sum(grepl("^xaxis", names(p$x$layout))) > 1) {
48+
stop("Can only add a rangeslider to a plot with one x-axis", call. = FALSE)
49+
}
50+
p$x$layout$xaxis$rangeslider <- list(visible = TRUE, ...)
51+
p
52+
}
53+
3354

3455
#' Set the default configuration for plotly
3556
#'

man/rangeslider.Rd

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)