From 7e7355cb89521e045e3a410c56b566054c87d326 Mon Sep 17 00:00:00 2001 From: Craig Williams Date: Tue, 16 Apr 2019 17:06:57 +0000 Subject: [PATCH] Final fixes to download --- app.R | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/app.R b/app.R index 63cee53..dcf3116 100644 --- a/app.R +++ b/app.R @@ -621,6 +621,17 @@ server <- function(input, output, session) { }) + isAbsolutePath = function( path ){ + if( path == "~" ) + return(TRUE); + if( grepl("^~/", path) ) + return(TRUE); + if( grepl("^.:(/|\\\\)", path) ) + return(TRUE); + if( grepl("^(/|\\\\)", path) ) + return(TRUE); + return(FALSE); + } exportOrca <- function (p, file = "plot.png", format = tools::file_ext(file), scale = NULL, width = NULL, height = NULL, @@ -635,17 +646,31 @@ server <- function(input, output, session) { b <- plotly_build(p) plotlyjs <- b$dependencies[sapply(b$dependencies, function(d) { d$name == "plotly-main" })][[1]] - plotlyjs_file <- file.path(plotlyjs$src$file, plotlyjs$script) + + if (!isAbsolutePath(plotlyjs$src$file)) { + plotlyjs_file <- NULL + for(n in 1:length(.Library.site)) { + if (!is.null(plotlyjs_file)) { + next + } + f <- paste0(.Library.site[[n]], "/plotly/", plotlyjs$src$file, "/", plotlyjs$script) + if (file.exists(f)) { + plotlyjs_file <- f + } + } + } else { + plotlyjs_file <- file.path(plotlyjs$src$file, plotlyjs$script) + } args <- c( - "graph", shQuote(jsonlite::toJSON( + "graph", paste0("'", jsonlite::toJSON( b$x[c("data", "layout")], digits = 50, auto_unbox = TRUE, force = TRUE, null = "null", na = "null" - )), + ), "'"), "-o", file, "--format", format, "--plotlyjs", plotlyjs_file