Updates to manual, sheets and final report
This commit is contained in:
5
Parses.R
5
Parses.R
@@ -85,6 +85,7 @@ getInitial <- function(string, letter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
split <- function(cell) {
|
split <- function(cell) {
|
||||||
|
|
||||||
params <- unlist(strsplit(cell, ","))
|
params <- unlist(strsplit(cell, ","))
|
||||||
values <- rep(0, length(states))
|
values <- rep(0, length(states))
|
||||||
|
|
||||||
@@ -151,7 +152,7 @@ buildGraph <- function(model, desc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
print("about to build network")
|
print("about to build network")
|
||||||
#print(paste0(inputText, edges))
|
print(paste0(inputText, edges))
|
||||||
|
|
||||||
net <- model2network(paste0(inputText, edges), debug = FALSE)
|
net <- model2network(paste0(inputText, edges), debug = FALSE)
|
||||||
|
|
||||||
@@ -246,8 +247,6 @@ getValidNodes <- function(mapping, prevOutputs, prefix) {
|
|||||||
coefs[idx,] <- as.numeric(split(mapping[1, col]))[match(c("growth", "confidence", "layer"), states)]
|
coefs[idx,] <- as.numeric(split(mapping[1, col]))[match(c("growth", "confidence", "layer"), states)]
|
||||||
}
|
}
|
||||||
|
|
||||||
#print(coefs)
|
|
||||||
|
|
||||||
return(data.frame(
|
return(data.frame(
|
||||||
code = c(prevOutputs$code, paste0(prefix, seq(1:length(outNodes)))),
|
code = c(prevOutputs$code, paste0(prefix, seq(1:length(outNodes)))),
|
||||||
name = c(prevOutputs$name, outNodes),
|
name = c(prevOutputs$name, outNodes),
|
||||||
|
|||||||
90
app.R
90
app.R
@@ -11,6 +11,7 @@ modules::import(plotly)
|
|||||||
modules::import(openxlsx)
|
modules::import(openxlsx)
|
||||||
modules::import(zip)
|
modules::import(zip)
|
||||||
modules::import(DT)
|
modules::import(DT)
|
||||||
|
modules::import(plyr)
|
||||||
|
|
||||||
parser <- modules::use("Parses.R")
|
parser <- modules::use("Parses.R")
|
||||||
|
|
||||||
@@ -271,6 +272,7 @@ server <- function(input, output, session) {
|
|||||||
|
|
||||||
wb <- parser$parseSheet(paste0(dataStorage, fileList[idx]))
|
wb <- parser$parseSheet(paste0(dataStorage, fileList[idx]))
|
||||||
#print(tmp)
|
#print(tmp)
|
||||||
|
|
||||||
wb$p_es$edges$values <- sapply(wb$p_es$edges$impact, getImpact)
|
wb$p_es$edges$values <- sapply(wb$p_es$edges$impact, getImpact)
|
||||||
|
|
||||||
if (!is.null(wb)) {
|
if (!is.null(wb)) {
|
||||||
@@ -332,10 +334,13 @@ server <- function(input, output, session) {
|
|||||||
|
|
||||||
#displayCols <- match(nodeCodes, colnames(sampleDists))
|
#displayCols <- match(nodeCodes, colnames(sampleDists))
|
||||||
sampleDists <- sampleDists[,match(thisModel$p_es$nodes$code, colnames(sampleDists))]
|
sampleDists <- sampleDists[,match(thisModel$p_es$nodes$code, colnames(sampleDists))]
|
||||||
|
|
||||||
means <- apply(sampleDists, 2, mean)
|
means <- apply(sampleDists, 2, mean)
|
||||||
stdDev <- apply(sampleDists, 2, sd)
|
stdDev <- apply(sampleDists, 2, sd)
|
||||||
|
quantiles <- t(apply(sampleDists, 2, quantile, c(0.01, 0.25, 0.5, 0.75, 0.99)))
|
||||||
|
|
||||||
print(paste("Building likelihoods from model, sample dists", length(thisModel$p_es$nodes$name), length(sampleDists)))
|
print(paste("Building likelihoods from model, sample dists", length(thisModel$p_es$nodes$name), length(sampleDists)))
|
||||||
|
#str(quantiles)
|
||||||
|
|
||||||
if (forPlotly) {
|
if (forPlotly) {
|
||||||
return(data.frame(
|
return(data.frame(
|
||||||
@@ -343,13 +348,14 @@ server <- function(input, output, session) {
|
|||||||
code = thisModel$p_es$nodes$code,
|
code = thisModel$p_es$nodes$code,
|
||||||
layer = thisModel$p_es$nodes$layer,
|
layer = thisModel$p_es$nodes$layer,
|
||||||
range = c(
|
range = c(
|
||||||
apply(sampleDists, 2, min),
|
#apply(sampleDists, 2, min),
|
||||||
means - 2*stdDev,
|
quantiles[,1],
|
||||||
means - stdDev,
|
quantiles[,2],
|
||||||
means,
|
quantiles[,2],
|
||||||
means + stdDev,
|
quantiles[,3],
|
||||||
means + 2*stdDev,
|
quantiles[,4],
|
||||||
apply(sampleDists, 2, max)
|
quantiles[,4],
|
||||||
|
quantiles[,5]
|
||||||
),
|
),
|
||||||
stringsAsFactors = FALSE
|
stringsAsFactors = FALSE
|
||||||
))
|
))
|
||||||
@@ -391,6 +397,7 @@ server <- function(input, output, session) {
|
|||||||
#.selections$runOnce = FALSE
|
#.selections$runOnce = FALSE
|
||||||
print("Running calc")
|
print("Running calc")
|
||||||
.likelihoods$p_es <<- calcLikelihood(0, newStatus, TRUE)
|
.likelihoods$p_es <<- calcLikelihood(0, newStatus, TRUE)
|
||||||
|
|
||||||
.selections$pressStatus <<- newStatus
|
.selections$pressStatus <<- newStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,7 +420,7 @@ server <- function(input, output, session) {
|
|||||||
#status = status,
|
#status = status,
|
||||||
stringsAsFactors = FALSE
|
stringsAsFactors = FALSE
|
||||||
)
|
)
|
||||||
print(pressures)
|
|
||||||
#This assumes all pressures are the same...
|
#This assumes all pressures are the same...
|
||||||
|
|
||||||
setPressures(pressures)
|
setPressures(pressures)
|
||||||
@@ -459,7 +466,7 @@ server <- function(input, output, session) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
observeEvent(input$modalOK, {
|
observeEvent(input$modalOK, {
|
||||||
print("Modal ok pressed")
|
|
||||||
|
|
||||||
.resistanceScores["nr"] <<- -input$l1VH
|
.resistanceScores["nr"] <<- -input$l1VH
|
||||||
.resistanceScores["lr"] <<- -input$l1H
|
.resistanceScores["lr"] <<- -input$l1H
|
||||||
@@ -469,7 +476,7 @@ server <- function(input, output, session) {
|
|||||||
.resistanceScores["ssgr"] <<- input$ssgr
|
.resistanceScores["ssgr"] <<- input$ssgr
|
||||||
.resistanceScores["pressSD"] <<- input$l1PressSD
|
.resistanceScores["pressSD"] <<- input$l1PressSD
|
||||||
|
|
||||||
print("Running calc")
|
|
||||||
.likelihoods$p_es <<- calcLikelihood(0, .selections$pressStatus, TRUE)
|
.likelihoods$p_es <<- calcLikelihood(0, .selections$pressStatus, TRUE)
|
||||||
removeModal()
|
removeModal()
|
||||||
|
|
||||||
@@ -573,7 +580,7 @@ server <- function(input, output, session) {
|
|||||||
stringsAsFactors = FALSE
|
stringsAsFactors = FALSE
|
||||||
)
|
)
|
||||||
|
|
||||||
print(legendDF)
|
|
||||||
|
|
||||||
visNetwork(nodeNet, edgeNet, width = "100%", main = "Bayesian Belief Network", submain = input$modelSelect) %>%
|
visNetwork(nodeNet, edgeNet, width = "100%", main = "Bayesian Belief Network", submain = input$modelSelect) %>%
|
||||||
visExport() %>%
|
visExport() %>%
|
||||||
@@ -626,7 +633,7 @@ server <- function(input, output, session) {
|
|||||||
colnames(thisPlot) <- c(name, "Group", "Range")
|
colnames(thisPlot) <- c(name, "Group", "Range")
|
||||||
title <- paste(input$modelSelect, name, "Box Plot")
|
title <- paste(input$modelSelect, name, "Box Plot")
|
||||||
paletteLength <- nrow(modelList[[.selections$model]]$legend)
|
paletteLength <- nrow(modelList[[.selections$model]]$legend)
|
||||||
print(paste('prep plot palette', paletteLength))
|
#print(paste('prep plot palette', paletteLength))
|
||||||
genPlot(thisPlot, title, paletteLength)
|
genPlot(thisPlot, title, paletteLength)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -664,12 +671,60 @@ server <- function(input, output, session) {
|
|||||||
contentType = "application/xlsx"
|
contentType = "application/xlsx"
|
||||||
)
|
)
|
||||||
|
|
||||||
output$download <- downloadHandler(
|
makeLikelihoods <- function() {
|
||||||
|
|
||||||
|
|
||||||
|
likeliTab <- as.data.frame(
|
||||||
|
cbind(
|
||||||
|
.likelihoods$p_es, codeVal = sapply(
|
||||||
|
.likelihoods$p_es$code, function(str) {
|
||||||
|
if (startsWith(str, 'p')) as.numeric(substring(str, 2, nchar(str)))
|
||||||
|
else as.numeric(substring(str, 3, nchar(str)))
|
||||||
|
}
|
||||||
|
)),
|
||||||
|
stringsAsFactors=FALSE
|
||||||
|
)
|
||||||
|
|
||||||
|
likeliTab <- arrange(likeliTab, layer, codeVal)
|
||||||
|
|
||||||
|
outputRows <- trunc(nrow(likeliTab)/7)
|
||||||
|
outputTab <- NULL
|
||||||
|
|
||||||
|
for (idx in 1:outputRows) {
|
||||||
|
elementRow <- (idx - 1) * 7 + 1
|
||||||
|
|
||||||
|
tabRow <-c(
|
||||||
|
name = likeliTab$name[elementRow],
|
||||||
|
code = likeliTab$code[elementRow],
|
||||||
|
layer = likeliTab$layer[elementRow],
|
||||||
|
min=likeliTab$range[elementRow],
|
||||||
|
q1 =likeliTab$range[elementRow+2],
|
||||||
|
median =likeliTab$range[elementRow+3],
|
||||||
|
q3 =likeliTab$range[elementRow+4],
|
||||||
|
max =likeliTab$range[elementRow+6]
|
||||||
|
)
|
||||||
|
outputTab <- rbind(outputTab, tabRow)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
likelihoods <- data.frame(
|
||||||
|
name = outputTab[,1],
|
||||||
|
code = outputTab[,2],
|
||||||
|
layer = as.numeric(outputTab[,3]),
|
||||||
|
max =as.numeric(outputTab[,8]),
|
||||||
|
q3 =as.numeric(outputTab[,7]),
|
||||||
|
median =as.numeric(outputTab[,6]),
|
||||||
|
q1 =as.numeric(outputTab[,5]),
|
||||||
|
min=as.numeric(outputTab[,4]),
|
||||||
|
stringsAsFactors = FALSE,
|
||||||
|
row.names = NULL
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
output$download <- downloadHandler(
|
||||||
|
|
||||||
filename = function() { paste0("MESO-", format(Sys.time(), "%m%d_%H%M"), ".xlsx") },
|
filename = function() { paste0("MESO-", format(Sys.time(), "%m%d_%H%M"), ".xlsx") },
|
||||||
content = function(file) {
|
content = function(file) {
|
||||||
print("STARTING download")
|
|
||||||
|
|
||||||
showModal(
|
showModal(
|
||||||
modalDialog(
|
modalDialog(
|
||||||
@@ -686,19 +741,14 @@ server <- function(input, output, session) {
|
|||||||
dir.create(tmp)
|
dir.create(tmp)
|
||||||
setwd(tmp)
|
setwd(tmp)
|
||||||
|
|
||||||
#Get the network graph
|
|
||||||
#l1 <- exportOrca(prepPlot("ba", "Bio-Assemblage"), "layer1.png")
|
|
||||||
#l2 <- exportOrca(prepPlot("op", "Output Processes"),"layer2.png")
|
|
||||||
#l3 <- exportOrca(prepPlot("es", "Ecosystem Services"),"layer3.png")
|
|
||||||
|
|
||||||
#Save pressure list, confidence levels, node and edge tables in xlsx
|
|
||||||
|
|
||||||
l <- list(
|
l <- list(
|
||||||
pressures = .selections$pressStatus,
|
pressures = .selections$pressStatus,
|
||||||
nodes = modelList[[.selections$model]]$p_es$nodes,
|
nodes = modelList[[.selections$model]]$p_es$nodes,
|
||||||
edges = modelList[[.selections$model]]$p_es$edges,
|
edges = modelList[[.selections$model]]$p_es$edges,
|
||||||
settings = as.data.frame(cbind(names(.resistanceScores), .resistanceScores), stringsAsFactors = FALSE),
|
settings = as.data.frame(cbind(names(.resistanceScores), .resistanceScores), stringsAsFactors = FALSE),
|
||||||
likelihoods = calcLikelihood(0, .selections$pressStatus, FALSE)
|
likelihoods = makeLikelihoods()
|
||||||
)
|
)
|
||||||
xl <- write.xlsx(l, "dataset.xlsx")
|
xl <- write.xlsx(l, "dataset.xlsx")
|
||||||
|
|
||||||
|
|||||||
BIN
data/Sub_littoral_mixed_release_#2.xlsx
Normal file
BIN
data/Sub_littoral_mixed_release_#2.xlsx
Normal file
Binary file not shown.
BIN
data/Sub_littoral_mud_release_#2.xlsx
Normal file
BIN
data/Sub_littoral_mud_release_#2.xlsx
Normal file
Binary file not shown.
BIN
data/Sub_littoral_rock_release_#2.xlsx
Normal file
BIN
data/Sub_littoral_rock_release_#2.xlsx
Normal file
Binary file not shown.
BIN
data/Sub_littoral_sand_release_#2.xlsx
Normal file
BIN
data/Sub_littoral_sand_release_#2.xlsx
Normal file
Binary file not shown.
BIN
www/Manual.pdf
BIN
www/Manual.pdf
Binary file not shown.
BIN
www/Report.pdf
BIN
www/Report.pdf
Binary file not shown.
Reference in New Issue
Block a user