diff --git a/R/partial_bundles.R b/R/partial_bundles.R index fc7a66795e..bb37e07835 100644 --- a/R/partial_bundles.R +++ b/R/partial_bundles.R @@ -10,20 +10,29 @@ #' bundles are used, the most recent bundle will override the other bundles. #' See the examples section for an example. #' +#' With `local = TRUE`, the first use of a partial bundle in an R session +#' downloads it from `https://cdn.plot.ly`. Later builds can reuse the cached +#' file in the session's temporary directory without a connection. A +#' self-contained HTML export embeds the local file. +#' +#' With `local = FALSE`, the widget references the CDN. Fetching the bundle +#' for viewing or embedding it in a self-contained export requires an internet +#' connection. To export offline using the full plotly.js bundle included in +#' the package, save the original widget with `htmlwidgets::saveWidget()`. +#' #' @param p a plotly object. #' @param type name of the (partial) bundle. The default, `'auto'`, attempts to #' find the smallest single bundle that can render `p`. If no single partial bundle #' can render `p`, then the full bundle is used. -#' @param local whether or not to download the partial bundle so that it can be -#' viewed later without an internet connection. +#' @param local whether to download the partial bundle (`TRUE`, the default) +#' or reference it by its CDN URL (`FALSE`). #' @param minified whether or not to use a minified js file (non-minified file can be useful for debugging plotly.js) #' @author Carson Sievert #' @export #' @examplesIf interactive() || !identical(.Platform$OS.type, "windows") #' #' # ---------------------------------------------------------------------- -#' # This function is always safe to use when rendering a single -#' # plotly graph. In this case, we get a 3x file reduction. +#' # Compare the full and partial bundle sizes for a single plotly graph. #' # ---------------------------------------------------------------------- #' #' \dontrun{ @@ -38,7 +47,9 @@ #' } #' f1 <- tempfile(fileext = ".html") #' f2 <- tempfile(fileext = ".html") +#' # Save with the full bundle while offline. #' save_widget(p, f1) +#' # The first use of this partial bundle needs access to the CDN. #' save_widget(partial_bundle(p), f2) #' #' # ---------------------------------------------------------------------- diff --git a/man/partial_bundle.Rd b/man/partial_bundle.Rd index 43eb5f852e..17a9093cc8 100644 --- a/man/partial_bundle.Rd +++ b/man/partial_bundle.Rd @@ -13,8 +13,8 @@ partial_bundle(p, type = "auto", local = TRUE, minified = TRUE) find the smallest single bundle that can render \code{p}. If no single partial bundle can render \code{p}, then the full bundle is used.} -\item{local}{whether or not to download the partial bundle so that it can be -viewed later without an internet connection.} +\item{local}{whether to download the partial bundle (\code{TRUE}, the default) +or reference it by its CDN URL (\code{FALSE}).} \item{minified}{whether or not to use a minified js file (non-minified file can be useful for debugging plotly.js)} } @@ -29,13 +29,22 @@ WARNING: use this function with caution when rendering multiple plotly graphs on a single website. That's because, if multiple plotly.js bundles are used, the most recent bundle will override the other bundles. See the examples section for an example. + +With \code{local = TRUE}, the first use of a partial bundle in an R session +downloads it from \verb{https://cdn.plot.ly}. Later builds can reuse the cached +file in the session's temporary directory without a connection. A +self-contained HTML export embeds the local file. + +With \code{local = FALSE}, the widget references the CDN. Fetching the bundle +for viewing or embedding it in a self-contained export requires an internet +connection. To export offline using the full plotly.js bundle included in +the package, save the original widget with \code{htmlwidgets::saveWidget()}. } \examples{ \dontshow{if (interactive() || !identical(.Platform$OS.type, "windows")) withAutoprint(\{ # examplesIf} # ---------------------------------------------------------------------- -# This function is always safe to use when rendering a single -# plotly graph. In this case, we get a 3x file reduction. +# Compare the full and partial bundle sizes for a single plotly graph. # ---------------------------------------------------------------------- \dontrun{ @@ -50,7 +59,9 @@ save_widget <- function(p, f) { } f1 <- tempfile(fileext = ".html") f2 <- tempfile(fileext = ".html") +# Save with the full bundle while offline. save_widget(p, f1) +# The first use of this partial bundle needs access to the CDN. save_widget(partial_bundle(p), f2) # ----------------------------------------------------------------------