diff --git a/DESCRIPTION b/DESCRIPTION index 57a76fb780..aacfee00af 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,7 +32,7 @@ Imports: digest, viridisLite, base64enc, - htmltools, + htmltools (>= 0.3.6), htmlwidgets (>= 1.3), tidyr, hexbin, diff --git a/R/highlight.R b/R/highlight.R index c66e6a2118..7fe829898f 100644 --- a/R/highlight.R +++ b/R/highlight.R @@ -206,7 +206,10 @@ highlight_defaults <- function() { selectizeLib <- function(bootstrap = TRUE) { htmltools::htmlDependency( - "selectize", "0.12.0", depPath("selectize"), + name = "selectize", + version = "0.12.0", + package = "plotly", + src = dependency_dir("selectize"), stylesheet = if (bootstrap) "selectize.bootstrap3.css", script = "selectize.min.js" ) @@ -214,12 +217,15 @@ selectizeLib <- function(bootstrap = TRUE) { colourPickerLib <- function() { htmltools::htmlDependency( - "colourpicker", "1.1", depPath("colourpicker"), + name = "colourpicker", + version = "1.1", + package = "plotly", + src = dependency_dir("colourpicker"), stylesheet = "colourpicker.min.css", script = "colourpicker.min.js" ) } -depPath <- function(...) { - system.file('htmlwidgets', 'lib', ..., package = 'plotly') +dependency_dir <- function(...) { + file.path('htmlwidgets', 'lib', ...) } diff --git a/R/mathjax.R b/R/mathjax.R index 94962fe385..7acb711393 100644 --- a/R/mathjax.R +++ b/R/mathjax.R @@ -29,7 +29,8 @@ mathjax_cdn <- function() { htmltools::htmlDependency( name = "mathjax", version = "2.7.4", - src = c(file = depPath("mathjax")), + package = "plotly", + src = dependency_dir("mathjax"), script = "cdn.js" ) } diff --git a/R/orca.R b/R/orca.R index 546160cfd7..c2761d79b4 100644 --- a/R/orca.R +++ b/R/orca.R @@ -73,7 +73,11 @@ orca <- function(p, file = "plot.png", format = tools::file_ext(file), # find the relevant plotly.js bundle plotlyjs <- plotlyjsBundle(b) - plotlyjs_file <- file.path(plotlyjs$src$file, plotlyjs$script) + plotlyjs_path <- file.path(plotlyjs$src$file, plotlyjs$script) + # package field means src file path should be relative to pkg dir + if (!is.null(plotlyjs$package)) { + plotlyjs_path <- system.file(plotlyjs_path, package = plotlyjs$package) + } tmp <- tempfile(fileext = ".json") cat(to_JSON(b$x[c("data", "layout")]), file = tmp) @@ -82,7 +86,7 @@ orca <- function(p, file = "plot.png", format = tools::file_ext(file), "graph", tmp, "-o", file, "--format", format, - "--plotlyjs", plotlyjs_file, + "--plotlyjs", plotlyjs_path, if (debug) "--debug", if (verbose) "--verbose", if (safe) "--safe-mode", @@ -143,12 +147,16 @@ orca_serve <- function(port = 5151, mathjax = FALSE, safe = FALSE, request_limit # use main bundle since any plot can be thrown at the server plotlyjs <- plotlyMainBundle() - plotlyjs_file <- file.path(plotlyjs$src$file, plotlyjs$script) + plotlyjs_path <- file.path(plotlyjs$src$file, plotlyjs$script) + # package field means src file path should be relative to pkg dir + if (!is.null(plotlyjs$package)) { + plotlyjs_path <- system.file(plotlyjs_path, package = plotlyjs$package) + } args <- c( "serve", "-p", port, - "--plotly", plotlyjs_file, + "--plotly", plotlyjs_path, if (safe) "--safe-mode", if (orca_version() >= "1.1.1") "--graph-only", if (keep_alive) "--keep-alive", diff --git a/R/partial_bundles.R b/R/partial_bundles.R index 9e128c7a35..6ddd81c37a 100644 --- a/R/partial_bundles.R +++ b/R/partial_bundles.R @@ -139,6 +139,8 @@ verify_partial_bundle <- function(p) { if (!file.exists(tmpfile)) { curl::curl_download(paste0("https://cdn.plot.ly/", bundle_script), tmpfile) } + # file src is no longer in plotly's path (it's a temp file) + p$dependencies[[idx]]$package <- NULL } p diff --git a/R/plotly.R b/R/plotly.R index e07de467ae..cadd340c64 100644 --- a/R/plotly.R +++ b/R/plotly.R @@ -434,8 +434,10 @@ as_widget <- function(x, ...) { typedArrayPolyfill <- function() { htmltools::htmlDependency( - "typedarray", "0.1", - src = depPath("typedarray"), + name = "typedarray", + version = "0.1", + package = "plotly", + src = dependency_dir("typedarray"), script = "typedarray.min.js", all_files = FALSE ) @@ -445,9 +447,10 @@ typedArrayPolyfill <- function() { # and bundle size at print time. plotlyMainBundle <- function() { htmltools::htmlDependency( - "plotly-main", + name = "plotly-main", version = "1.41.3", - src = depPath("plotlyjs"), + package = "plotly", + src = dependency_dir("plotlyjs"), script = "plotly-latest.min.js", all_files = FALSE ) @@ -455,9 +458,10 @@ plotlyMainBundle <- function() { plotlyHtmlwidgetsCSS <- function() { htmltools::htmlDependency( - "plotly-htmlwidgets-css", + name = "plotly-htmlwidgets-css", version = plotlyMainBundle()$version, - src = depPath("plotlyjs"), + package = "plotly", + src = dependency_dir("plotlyjs"), stylesheet = "plotly-htmlwidgets.css", all_files = FALSE ) @@ -468,8 +472,8 @@ locale_dependency <- function(locale) { stop("locale must be a character string (vector of length 1)", call. = FALSE) } - locale_dir <- depPath("plotlyjs", "locales") - locales_all <- sub("\\.js$", "", list.files(locale_dir)) + locale_dir <- dependency_dir("plotlyjs", "locales") + locales_all <- sub("\\.js$", "", list.files(system.file(locale_dir, package = "plotly"))) if (!tolower(locale) %in% locales_all) { stop( "Invalid locale: '", locale, "'.\n\n", @@ -491,6 +495,7 @@ locale_dependency <- function(locale) { htmltools::htmlDependency( name = paste0("plotly-locale-", locale), version = plotlyMainBundle()$version, + package = "plotly", src = list(file = locale_dir), script = tolower(scripts), all_files = FALSE