Fix download
This commit is contained in:
83
app.R
83
app.R
@@ -81,7 +81,7 @@ ui <- dashboardPage(
|
|||||||
#menuItem("Habitats", tabName = "3", icon = icon("atlas")),
|
#menuItem("Habitats", tabName = "3", icon = icon("atlas")),
|
||||||
#menuItem("Ingestion", tabName = "3", icon = icon("utensils")),
|
#menuItem("Ingestion", tabName = "3", icon = icon("utensils")),
|
||||||
selectInput("modelSelect", "Select MESO model", choices = c(""), selected = NULL, multiple = FALSE),
|
selectInput("modelSelect", "Select MESO model", choices = c(""), selected = NULL, multiple = FALSE),
|
||||||
#downloadButton("download", "", icon = icon("download")),
|
downloadButton("download", "", icon = icon("download")),
|
||||||
uiOutput("pressureList")
|
uiOutput("pressureList")
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
@@ -621,32 +621,9 @@ server <- function(input, output, session) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
export <- function(model) {
|
export <- function(model, fPath) {
|
||||||
|
|
||||||
#Get the network graph
|
|
||||||
l1 <- orca(prepPlot("ba", "Bio-Assemblage"), "tmp/layer1.png")
|
|
||||||
l2 <- orca(prepPlot("op", "Output Processes"),"tmp/layer2.png")
|
|
||||||
l3 <- orca(prepPlot("es", "Ecosystem Services"), "tmp/layer3.png")
|
|
||||||
|
|
||||||
#Save pressure list, confidence levels, node and edge tables in xlsx
|
|
||||||
l <- list(
|
|
||||||
pressures = .selections$pressStatus,
|
|
||||||
nodes = model$p_es$nodes,
|
|
||||||
edges = model$p_es$edges,
|
|
||||||
settings = as.data.frame(cbind(names(.resistanceScores), .resistanceScores), stringsAsFactors = FALSE)
|
|
||||||
)
|
|
||||||
|
|
||||||
xl <- write.xlsx(l, "tmp/dataset.xlsx")
|
|
||||||
|
|
||||||
print("saving xlsx file export tmp/dataset.xlsx")
|
|
||||||
|
|
||||||
zipFile <- zipr(paste0("tmp/MESO-", format(Sys.time(), "%m%d_%H%M"), ".zip"), c("tmp/layer1.png", "tmp/layer2.png", "tmp/layer3.png", "tmp/dataset.xlsx"))
|
|
||||||
|
|
||||||
print(paste("zip file complete", zipFile))
|
|
||||||
file.remove("tmp/layer1.png")
|
|
||||||
file.remove("tmp/layer2.png")
|
|
||||||
file.remove("tmp/layer3.png")
|
|
||||||
file.remove("tmp/dataset.xlsx")
|
|
||||||
return(zipFile)
|
return(zipFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,19 +637,49 @@ server <- function(input, output, session) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
output$download <- downloadHandler(
|
output$download <- downloadHandler(
|
||||||
filename = 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(
|
||||||
# fluidRow(
|
fluidRow(
|
||||||
# column(width = 12) %>% withSpinner(type = 5, proxy.height = "200px")
|
column(width = 12) %>% withSpinner(type = 5, proxy.height = "200px")
|
||||||
# ),
|
),
|
||||||
# footer=div()
|
footer=div()
|
||||||
# )
|
)
|
||||||
#)
|
)
|
||||||
fName <- export(modelList[[.selections$model]])
|
|
||||||
file.copy(fName, file)
|
oldDir <- getwd()
|
||||||
#removeModal()
|
|
||||||
|
tmp <- tempfile("")
|
||||||
|
|
||||||
|
print(tmp)
|
||||||
|
dir.create(tmp)
|
||||||
|
|
||||||
|
setwd(tmp)
|
||||||
|
|
||||||
|
#Get the network graph
|
||||||
|
l1 <- orca(prepPlot("ba", "Bio-Assemblage"), "layer1.png")
|
||||||
|
l2 <- orca(prepPlot("op", "Output Processes"),"layer2.png")
|
||||||
|
l3 <- orca(prepPlot("es", "Ecosystem Services"),"layer3.png")
|
||||||
|
|
||||||
|
|
||||||
|
#Save pressure list, confidence levels, node and edge tables in xlsx
|
||||||
|
l <- list(
|
||||||
|
pressures = .selections$pressStatus,
|
||||||
|
nodes = modelList[[.selections$model]]$p_es$nodes,
|
||||||
|
edges = modelList[[.selections$model]]$p_es$edges,
|
||||||
|
settings = as.data.frame(cbind(names(.resistanceScores), .resistanceScores), stringsAsFactors = FALSE)
|
||||||
|
)
|
||||||
|
xl <- write.xlsx(l, "dataset.xlsx")
|
||||||
|
|
||||||
|
zipFile <- zipr(file, c("layer1.png", "layer2.png", "layer3.png", "dataset.xlsx"))
|
||||||
|
|
||||||
|
print(paste("zip file complete", zipFile))
|
||||||
|
|
||||||
|
setwd(oldDir)
|
||||||
|
unlink(tmp)
|
||||||
|
|
||||||
|
removeModal()
|
||||||
},
|
},
|
||||||
contentType = "application/zip"
|
contentType = "application/zip"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user