Fix download by not using processx

This commit is contained in:
2019-04-16 17:20:02 +01:00
parent b5349eb81a
commit fe6a17841d

56
app.R
View File

@@ -621,13 +621,51 @@ server <- function(input, output, session) {
}) })
export <- function(model, fPath) {
exportOrca <- function (p, file = "plot.png", format = tools::file_ext(file),
scale = NULL, width = NULL, height = NULL,
verbose = FALSE, debug = FALSE, safe = FALSE)
{
if (Sys.which("orca") == "") {
stop("The orca command-line utility is required to use the `orca()` function.\n\n",
"Follow the installation instructions here -- https://github.com/plotly/orca#installation",
call. = FALSE)
}
return(zipFile) 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)
args <- c(
"graph", shQuote(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
)
if (debug)
args <- c(args, "--debug")
if (verbose)
args <- c(args, "--verbose")
if (safe)
args <- c(args, "--safe-mode")
if (!is.null(scale))
args <- c(args, "--scale", scale)
if (!is.null(width))
args <- c(args, "--width", width)
if (!is.null(height))
args <- c(args, "--height", height)
invisible(system2("orca", args))
} }
output$linkBackgroundData <- downloadHandler( output$linkBackgroundData <- downloadHandler(
filename = getModelName(), filename = getModelName(),
content = function(file) { content = function(file) {
@@ -637,7 +675,7 @@ server <- function(input, output, session) {
) )
output$download <- downloadHandler( output$download <- downloadHandler(
filename = function() {paste0("MESO-", format(Sys.time(), "%m%d_%H%M"), ".zip")}, filename = function() { paste0("MESO-", format(Sys.time(), "%m%d_%H%M"), ".zip") },
content = function(file) { content = function(file) {
showModal( showModal(
modalDialog( modalDialog(
@@ -651,17 +689,13 @@ server <- function(input, output, session) {
oldDir <- getwd() oldDir <- getwd()
tmp <- tempfile("") tmp <- tempfile("")
print(tmp)
dir.create(tmp) dir.create(tmp)
setwd(tmp) setwd(tmp)
#Get the network graph #Get the network graph
l1 <- orca(prepPlot("ba", "Bio-Assemblage"), "layer1.png") l1 <- exportOrca(prepPlot("ba", "Bio-Assemblage"), "layer1.png")
l2 <- orca(prepPlot("op", "Output Processes"),"layer2.png") l2 <- exportOrca(prepPlot("op", "Output Processes"),"layer2.png")
l3 <- orca(prepPlot("es", "Ecosystem Services"),"layer3.png") l3 <- exportOrca(prepPlot("es", "Ecosystem Services"),"layer3.png")
#Save pressure list, confidence levels, node and edge tables in xlsx #Save pressure list, confidence levels, node and edge tables in xlsx
l <- list( l <- list(