Skip to content

print-time html dependencies should use relative instead of absolute paths #1384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions R/highlight.R
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,26 @@ 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"
)
}

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', ...)
}
3 changes: 2 additions & 1 deletion R/mathjax.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
Expand Down
16 changes: 12 additions & 4 deletions R/orca.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions R/partial_bundles.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions R/plotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -445,19 +447,21 @@ 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
)
}

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
)
Expand All @@ -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",
Expand All @@ -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
Expand Down