Skip to content
Open
Changes from all 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
48 changes: 27 additions & 21 deletions R/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ shinyAppServer = function(input, output, session) {
crashes <<- readRDS(crashes_file_name)
crashes_exist <- TRUE
}
net$layer = net$flow
net = get_layer (net, input$layer)
#net$layer = net$flow
if(input$safety) {
if (crashes_exist) {
plot_map(net, input$layer, update_view = TRUE) %>%
Expand All @@ -87,26 +88,7 @@ shinyAppServer = function(input, output, session) {
input$layer
},
{
if (input$layer == "Pedestrian flow") {
net$layer = net$flow
} else if (input$layer == "Vehicular flow") {
if ("centrality" %in% names(net)) {
net$layer = net$centrality
} else {
net$layer = net$flow
}
} else if (input$layer == "Vehicular emissions") {
if ("centrality_disp" %in% names(net)) {
net$layer = net$centrality_disp
} else {
net$layer = net$flow
}
} else if (input$layer == "Pedestrian exposure") {
net$layer = net$flow
if ("centrality_disp" %in% names(net)) {
net$layer = net$flow * net$centrality_disp
}
}
net = get_layer (net, input$layer)
plot_map(net, input$layer, update_view = FALSE)
}
)
Expand Down Expand Up @@ -148,6 +130,30 @@ shinyAppServer = function(input, output, session) {

}

get_layer = function(net, layer) {
if (layer == "Pedestrian flow") {
net$layer = net$flow
} else if (layer == "Vehicular flow") {
if ("centrality" %in% names(net)) {
net$layer = net$centrality
} else {
net$layer = net$flow
}
} else if (layer == "Vehicular emissions") {
if ("centrality_disp" %in% names(net)) {
net$layer = net$centrality_disp
} else {
net$layer = net$flow
}
} else if (layer == "Pedestrian exposure") {
net$layer = net$flow
if ("centrality_disp" %in% names(net)) {
net$layer = net$flow * net$centrality_disp
}
}
return(net)
}

plot_map = function(net, leg_title, update_view = FALSE) {
threshold <- 0.01 # constant relative threshold - maybe expose later?
net = net [net$flow > (threshold * max (net$flow, na.rm = TRUE)), ]
Expand Down