From f54daa10ac5b6e10c67122db23446bfd1f8b17a9 Mon Sep 17 00:00:00 2001 From: William Holmes <46801648+wholmes105@users.noreply.github.com> Date: Fri, 7 Jul 2023 18:57:16 -0400 Subject: [PATCH 1/4] Delete misplaced file layout.R was uploaded in the wrong folder initially --- layout.R | 408 ------------------------------------------------------- 1 file changed, 408 deletions(-) delete mode 100644 layout.R diff --git a/layout.R b/layout.R deleted file mode 100644 index 347f7bf4cc..0000000000 --- a/layout.R +++ /dev/null @@ -1,408 +0,0 @@ -#' Modify the layout of a plotly visualization -#' -#' @param p A plotly object. -#' @param ... Arguments to the layout object. For documentation, -#' see \url{https://plotly.com/r/reference/#Layout_and_layout_style_objects} -#' @param data A data frame to associate with this layout (optional). If not -#' provided, arguments are evaluated using the data frame in [plot_ly()]. -#' @author Carson Sievert -#' @export -layout <- function(p, ..., data = NULL) { - UseMethod("layout") -} - -#' @export -layout.matrix <- function(p, ..., data = NULL) { - # workaround for the popular graphics::layout() function - # https://github.com/ropensci/plotly/issues/464 - graphics::layout(p, ...) -} - -#' @export -layout.shiny.tag.list <- function(p, ..., data = NULL) { - idx <- which(vapply(p, is.plotly, logical(1))) - for (i in idx) { - p[[i]] <- layout.plotly(p[[i]], ..., data = NULL) - } - p -} - -#' @export -layout.plotly <- function(p, ..., data = NULL) { - p <- add_data(p, data) - attrs <- list(...) - if (!is.null(attrs[["height"]]) || !is.null(attrs[["width"]])) { - warning("Specifying width/height in layout() is now deprecated.\n", - "Please specify in ggplotly() or plot_ly()", call. = FALSE) - } - # similar to add_trace() - p$x$layoutAttrs <- c( - p$x$layoutAttrs %||% list(), - setNames(list(attrs), p$x$cur_data) - ) - p -} - -#' Add a range slider to the x-axis -#' -#' @param p plotly object. -#' @param start a start date/value. -#' @param end an end date/value. -#' @param ... these arguments are documented here -#' \url{https://plotly.com/r/reference/#layout-xaxis-rangeslider} -#' @export -#' @author Carson Sievert -#' @examplesIf interactive() || !identical(.Platform$OS.type, "windows") -#' -#' plot_ly(x = time(USAccDeaths), y = USAccDeaths) %>% -#' add_lines() %>% -#' rangeslider() -#' -#' d <- tibble::tibble( -#' time = seq(as.Date("2016-01-01"), as.Date("2016-08-31"), by = "days"), -#' y = rnorm(seq_along(time)) -#' ) -#' -#' plot_ly(d, x = ~time, y = ~y) %>% -#' add_lines() %>% -#' rangeslider(d$time[5], d$time[50]) -#' -#' -rangeslider <- function(p, start = NULL, end = NULL, ...) { - if (sum(grepl("^xaxis", names(p$x$layout))) > 1) { - stop("Can only add a rangeslider to a plot with one x-axis", call. = FALSE) - } - - p$x$layout$xaxis$range <- c( - to_milliseconds(start), - to_milliseconds(end) - ) - - p$x$layout$xaxis$rangeslider <- list(visible = TRUE, ...) - p -} - - -#' Set the default configuration for plotly -#' -#' @param p a plotly object -#' @param ... these arguments are documented at -#' \url{https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_config.js} -#' @param cloud deprecated. Use `showSendToCloud` instead. -#' @param showSendToCloud include the send data to cloud button? -#' @param locale locale to use. See [here](https://github.com/plotly/plotly.js/tree/master/dist#to-include-localization) for more info. -#' @param mathjax add [MathJax rendering support](https://github.com/plotly/plotly.js/tree/master/dist#to-support-mathjax). -#' If `"cdn"`, mathjax is loaded externally (meaning an internet connection is needed for -#' TeX rendering). If `"local"`, the PLOTLY_MATHJAX_PATH environment variable must be -#' set to the location (a local file path) of MathJax. IMPORTANT: **plotly** uses SVG-based -#' mathjax rendering which doesn't play nicely with HTML-based rendering -#' (e.g., **rmarkdown** documents and **shiny** apps). To leverage both types of rendering, -#' you must `