Skip to content

Commit 1e8f9b9

Browse files
authored
Merge pull request #1384 from ropensci/relative-dependency-paths
print-time html dependencies should use relative instead of absolute paths
2 parents 4cca561 + 1baf70c commit 1e8f9b9

File tree

6 files changed

+40
-18
lines changed

6 files changed

+40
-18
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Imports:
3232
digest,
3333
viridisLite,
3434
base64enc,
35-
htmltools,
35+
htmltools (>= 0.3.6),
3636
htmlwidgets (>= 1.3),
3737
tidyr,
3838
hexbin,

R/highlight.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,26 @@ highlight_defaults <- function() {
206206

207207
selectizeLib <- function(bootstrap = TRUE) {
208208
htmltools::htmlDependency(
209-
"selectize", "0.12.0", depPath("selectize"),
209+
name = "selectize",
210+
version = "0.12.0",
211+
package = "plotly",
212+
src = dependency_dir("selectize"),
210213
stylesheet = if (bootstrap) "selectize.bootstrap3.css",
211214
script = "selectize.min.js"
212215
)
213216
}
214217

215218
colourPickerLib <- function() {
216219
htmltools::htmlDependency(
217-
"colourpicker", "1.1", depPath("colourpicker"),
220+
name = "colourpicker",
221+
version = "1.1",
222+
package = "plotly",
223+
src = dependency_dir("colourpicker"),
218224
stylesheet = "colourpicker.min.css",
219225
script = "colourpicker.min.js"
220226
)
221227
}
222228

223-
depPath <- function(...) {
224-
system.file('htmlwidgets', 'lib', ..., package = 'plotly')
229+
dependency_dir <- function(...) {
230+
file.path('htmlwidgets', 'lib', ...)
225231
}

R/mathjax.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ mathjax_cdn <- function() {
2929
htmltools::htmlDependency(
3030
name = "mathjax",
3131
version = "2.7.4",
32-
src = c(file = depPath("mathjax")),
32+
package = "plotly",
33+
src = dependency_dir("mathjax"),
3334
script = "cdn.js"
3435
)
3536
}

R/orca.R

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ orca <- function(p, file = "plot.png", format = tools::file_ext(file),
7373

7474
# find the relevant plotly.js bundle
7575
plotlyjs <- plotlyjsBundle(b)
76-
plotlyjs_file <- file.path(plotlyjs$src$file, plotlyjs$script)
76+
plotlyjs_path <- file.path(plotlyjs$src$file, plotlyjs$script)
77+
# package field means src file path should be relative to pkg dir
78+
if (!is.null(plotlyjs$package)) {
79+
plotlyjs_path <- system.file(plotlyjs_path, package = plotlyjs$package)
80+
}
7781

7882
tmp <- tempfile(fileext = ".json")
7983
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),
8286
"graph", tmp,
8387
"-o", file,
8488
"--format", format,
85-
"--plotlyjs", plotlyjs_file,
89+
"--plotlyjs", plotlyjs_path,
8690
if (debug) "--debug",
8791
if (verbose) "--verbose",
8892
if (safe) "--safe-mode",
@@ -143,12 +147,16 @@ orca_serve <- function(port = 5151, mathjax = FALSE, safe = FALSE, request_limit
143147

144148
# use main bundle since any plot can be thrown at the server
145149
plotlyjs <- plotlyMainBundle()
146-
plotlyjs_file <- file.path(plotlyjs$src$file, plotlyjs$script)
150+
plotlyjs_path <- file.path(plotlyjs$src$file, plotlyjs$script)
151+
# package field means src file path should be relative to pkg dir
152+
if (!is.null(plotlyjs$package)) {
153+
plotlyjs_path <- system.file(plotlyjs_path, package = plotlyjs$package)
154+
}
147155

148156
args <- c(
149157
"serve",
150158
"-p", port,
151-
"--plotly", plotlyjs_file,
159+
"--plotly", plotlyjs_path,
152160
if (safe) "--safe-mode",
153161
if (orca_version() >= "1.1.1") "--graph-only",
154162
if (keep_alive) "--keep-alive",

R/partial_bundles.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ verify_partial_bundle <- function(p) {
139139
if (!file.exists(tmpfile)) {
140140
curl::curl_download(paste0("https://cdn.plot.ly/", bundle_script), tmpfile)
141141
}
142+
# file src is no longer in plotly's path (it's a temp file)
143+
p$dependencies[[idx]]$package <- NULL
142144
}
143145

144146
p

R/plotly.R

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,10 @@ as_widget <- function(x, ...) {
434434

435435
typedArrayPolyfill <- function() {
436436
htmltools::htmlDependency(
437-
"typedarray", "0.1",
438-
src = depPath("typedarray"),
437+
name = "typedarray",
438+
version = "0.1",
439+
package = "plotly",
440+
src = dependency_dir("typedarray"),
439441
script = "typedarray.min.js",
440442
all_files = FALSE
441443
)
@@ -445,19 +447,21 @@ typedArrayPolyfill <- function() {
445447
# and bundle size at print time.
446448
plotlyMainBundle <- function() {
447449
htmltools::htmlDependency(
448-
"plotly-main",
450+
name = "plotly-main",
449451
version = "1.41.3",
450-
src = depPath("plotlyjs"),
452+
package = "plotly",
453+
src = dependency_dir("plotlyjs"),
451454
script = "plotly-latest.min.js",
452455
all_files = FALSE
453456
)
454457
}
455458

456459
plotlyHtmlwidgetsCSS <- function() {
457460
htmltools::htmlDependency(
458-
"plotly-htmlwidgets-css",
461+
name = "plotly-htmlwidgets-css",
459462
version = plotlyMainBundle()$version,
460-
src = depPath("plotlyjs"),
463+
package = "plotly",
464+
src = dependency_dir("plotlyjs"),
461465
stylesheet = "plotly-htmlwidgets.css",
462466
all_files = FALSE
463467
)
@@ -468,8 +472,8 @@ locale_dependency <- function(locale) {
468472
stop("locale must be a character string (vector of length 1)", call. = FALSE)
469473
}
470474

471-
locale_dir <- depPath("plotlyjs", "locales")
472-
locales_all <- sub("\\.js$", "", list.files(locale_dir))
475+
locale_dir <- dependency_dir("plotlyjs", "locales")
476+
locales_all <- sub("\\.js$", "", list.files(system.file(locale_dir, package = "plotly")))
473477
if (!tolower(locale) %in% locales_all) {
474478
stop(
475479
"Invalid locale: '", locale, "'.\n\n",
@@ -491,6 +495,7 @@ locale_dependency <- function(locale) {
491495
htmltools::htmlDependency(
492496
name = paste0("plotly-locale-", locale),
493497
version = plotlyMainBundle()$version,
498+
package = "plotly",
494499
src = list(file = locale_dir),
495500
script = tolower(scripts),
496501
all_files = FALSE

0 commit comments

Comments
 (0)