From 1001051a270fb8de92ec7a07ba8cfbd86205f6c4 Mon Sep 17 00:00:00 2001 From: Nikolai B Date: Sun, 15 Sep 2019 08:39:16 +0100 Subject: [PATCH 1/3] Fix lines are again redrawn Sadly this re-introduce double sorting when changing a region. Fixes #797 --- regions_www/m/server.R | 43 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/regions_www/m/server.R b/regions_www/m/server.R index 79beb118..a2a3a4ab 100644 --- a/regions_www/m/server.R +++ b/regions_www/m/server.R @@ -574,28 +574,29 @@ shinyServer(function(input, output, session) { input$scenario input$line_order - isolate({ - shinyjs::showElement(id = "loading") - - line_type <- ifelse(input$line_type == 'routes', "routes_quieter", input$line_type) - - local_lines <- sort_lines(region$plot[[line_type]], input$line_type, input$nos_lines) - # Filter out zero lines for scenario in question from route network - if (input$line_type == "route_network") { - if (input$scenario == 'olc') { - local_lines <- local_lines[local_lines$bicycle>0,] - } else if (input$scenario == 'govtarget') { - local_lines <- local_lines[local_lines$govtarget_slc>0,] - } else if (input$scenario == 'govnearmkt') { - local_lines <- local_lines[local_lines$govnearmkt_slc>0,] - } else if (input$scenario == 'gendereq') { - local_lines <- local_lines[local_lines$gendereq_slc>0,] - } else if (input$scenario == 'cambridge') { - local_lines <- local_lines[local_lines$cambridge_slc>0,] - } else { - local_lines <- local_lines[local_lines$dutch_slc>0,] # always >0 for both - } + + shinyjs::showElement(id = "loading") + + line_type <- ifelse(input$line_type == 'routes', "routes_quieter", input$line_type) + + local_lines <- sort_lines(region$plot[[line_type]], input$line_type, input$nos_lines) + # Filter out zero lines for scenario in question from route network + if (input$line_type == "route_network") { + if (input$scenario == 'olc') { + local_lines <- local_lines[local_lines$bicycle>0,] + } else if (input$scenario == 'govtarget') { + local_lines <- local_lines[local_lines$govtarget_slc>0,] + } else if (input$scenario == 'govnearmkt') { + local_lines <- local_lines[local_lines$govnearmkt_slc>0,] + } else if (input$scenario == 'gendereq') { + local_lines <- local_lines[local_lines$gendereq_slc>0,] + } else if (input$scenario == 'cambridge') { + local_lines <- local_lines[local_lines$cambridge_slc>0,] + } else { + local_lines <- local_lines[local_lines$dutch_slc>0,] # always >0 for both } + } + isolate({ if (is.null(region$plot$ldata) || (!is.null(region$plot$ldata) && (!identical(region$plot$ldata, local_lines) || !identical(region$plot$scenario, input$scenario)))) { leafletProxy("map") %>% clearGroup(., c("straight_lines", From 440fe026ff1ae352cef44e6dd7b56b225cba6f85 Mon Sep 17 00:00:00 2001 From: Nikolai B Date: Sun, 15 Sep 2019 14:56:57 +0100 Subject: [PATCH 2/3] Only re-sort lines when needed --- regions_www/m/server.R | 47 +++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/regions_www/m/server.R b/regions_www/m/server.R index a2a3a4ab..7bf1a6b2 100644 --- a/regions_www/m/server.R +++ b/regions_www/m/server.R @@ -574,29 +574,34 @@ shinyServer(function(input, output, session) { input$scenario input$line_order - - shinyjs::showElement(id = "loading") - - line_type <- ifelse(input$line_type == 'routes', "routes_quieter", input$line_type) - - local_lines <- sort_lines(region$plot[[line_type]], input$line_type, input$nos_lines) - # Filter out zero lines for scenario in question from route network - if (input$line_type == "route_network") { - if (input$scenario == 'olc') { - local_lines <- local_lines[local_lines$bicycle>0,] - } else if (input$scenario == 'govtarget') { - local_lines <- local_lines[local_lines$govtarget_slc>0,] - } else if (input$scenario == 'govnearmkt') { - local_lines <- local_lines[local_lines$govnearmkt_slc>0,] - } else if (input$scenario == 'gendereq') { - local_lines <- local_lines[local_lines$gendereq_slc>0,] - } else if (input$scenario == 'cambridge') { - local_lines <- local_lines[local_lines$cambridge_slc>0,] - } else { - local_lines <- local_lines[local_lines$dutch_slc>0,] # always >0 for both - } + # If we are showing lines and the input is not frozen then we want to trigger this observe + # when the map bounds change + if (!isTruthy(input$line_type %in% show_no_lines) && !isTRUE(input$freeze)){ + input$map_bounds } + isolate({ + shinyjs::showElement(id = "loading") + + line_type <- ifelse(input$line_type == 'routes', "routes_quieter", input$line_type) + + local_lines <- sort_lines(region$plot[[line_type]], input$line_type, input$nos_lines) + # Filter out zero lines for scenario in question from route network + if (input$line_type == "route_network") { + if (input$scenario == 'olc') { + local_lines <- local_lines[local_lines$bicycle>0,] + } else if (input$scenario == 'govtarget') { + local_lines <- local_lines[local_lines$govtarget_slc>0,] + } else if (input$scenario == 'govnearmkt') { + local_lines <- local_lines[local_lines$govnearmkt_slc>0,] + } else if (input$scenario == 'gendereq') { + local_lines <- local_lines[local_lines$gendereq_slc>0,] + } else if (input$scenario == 'cambridge') { + local_lines <- local_lines[local_lines$cambridge_slc>0,] + } else { + local_lines <- local_lines[local_lines$dutch_slc>0,] # always >0 for both + } + } if (is.null(region$plot$ldata) || (!is.null(region$plot$ldata) && (!identical(region$plot$ldata, local_lines) || !identical(region$plot$scenario, input$scenario)))) { leafletProxy("map") %>% clearGroup(., c("straight_lines", From af9c84000f7b0f63126602d52fd51cad41b6c120 Mon Sep 17 00:00:00 2001 From: Nikolai B Date: Sun, 15 Sep 2019 14:58:42 +0100 Subject: [PATCH 3/3] Split ldata out from $plot reactive variable Changing the reactive $plot variable is triggering dynamic $plot getters to be reloaded: this means that line sorting is causing the zones to be re-plotted --- regions_www/m/server.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/regions_www/m/server.R b/regions_www/m/server.R index 7bf1a6b2..1a337e28 100644 --- a/regions_www/m/server.R +++ b/regions_www/m/server.R @@ -222,7 +222,7 @@ shinyServer(function(input, output, session) { ############## ## Create region and (for persistent geographical values) helper - region <- reactiveValues(current = NA, data_dir = NA, geography = NA, repopulate_region = F, purposes_present = NA, plot = NULL, line_data_dir = "") + region <- reactiveValues(current = NA, data_dir = NA, geography = NA, repopulate_region = F, purposes_present = NA, plot = NULL, line_data_dir = "", ldata = NULL) helper <- NULL helper$e_lat_lng <- "" helper$old_geog <- "" @@ -602,7 +602,7 @@ shinyServer(function(input, output, session) { local_lines <- local_lines[local_lines$dutch_slc>0,] # always >0 for both } } - if (is.null(region$plot$ldata) || (!is.null(region$plot$ldata) && (!identical(region$plot$ldata, local_lines) || !identical(region$plot$scenario, input$scenario)))) { + if (is.null(region$ldata) || (!is.null(region$ldata) && (!identical(region$ldata, local_lines) || !identical(region$plot$scenario, input$scenario)))) { leafletProxy("map") %>% clearGroup(., c("straight_lines", "routes_quieter", @@ -610,10 +610,10 @@ shinyServer(function(input, output, session) { "route_network" )) %>% removeShape(., "highlighted") - region$plot$ldata <- local_lines + region$ldata <- local_lines # Include current scenario in region$plot as the set of lines to plot may not change when the scenario alters, and so otherwise don't update region$plot$scenario <- input$scenario - plot_lines(leafletProxy("map"), region$plot$ldata, line_type) + plot_lines(leafletProxy("map"), region$ldata, line_type) # Additionally plot fast routes on top of quieter if selected 'fast & quieter' if (input$line_type == 'routes') { plot_lines(leafletProxy("map"), sort_lines(region$plot$routes_fast, "routes_fast", input$nos_lines),"routes_fast")