From ca40d68b470e7e9969f9eea8ffa63c1b60cf9568 Mon Sep 17 00:00:00 2001
From: unknown <olivier.delaigue@ANPI1430.antony.irstea.priv>
Date: Tue, 23 Jan 2018 10:13:32 +0100
Subject: [PATCH] v0.1.9.9 bug fixed in ShinyGR to show previous sim when time
 window changes but keep the same length

---
 DESCRIPTION           |  2 +-
 inst/ShinyGR/server.R | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index bd920c1..677d05e 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,7 +1,7 @@
 Package: airGRteaching
 Type: Package
 Title: Tools to Simplify the Use of the airGR Hydrological Package for Education (Including a Shiny Interface)
-Version: 0.1.9.8
+Version: 0.1.9.9
 Date: 2018-01-23
 Authors@R: c(person("Olivier", "Delaigue", role = c("aut", "cre"), email = "airGR@irstea.fr"), person("Laurent", "Coron", role = c("aut")), person("Pierre", "Brigode", role = c("aut")), person("Guillaume", "Thirel", role = c("ctb")))
 Depends: airGR (>= 1.0.9.43)
diff --git a/inst/ShinyGR/server.R b/inst/ShinyGR/server.R
index 052e71f..5431253 100644
--- a/inst/ShinyGR/server.R
+++ b/inst/ShinyGR/server.R
@@ -33,7 +33,6 @@ shinyServer(function(input, output, session) {
       # ObsBV <- get(input$Dataset)
       ObsBV <- .ShinyGR.args$ObsBV[[input$Dataset]]
     }
-    print(str(.ShinyGR.args$HypsoData[[input$Dataset]]))
     OBS <- ObsGR(ObsBV = ObsBV,
                  DatesR = .ShinyGR.args$DatesR,
                  Precip = .ShinyGR.args$Precip, PotEvap = .ShinyGR.args$PotEvap,
@@ -192,16 +191,18 @@ shinyServer(function(input, output, session) {
                                                                            Crit      = CRIT)
     
     .GlobalEnv$.ShinyGR.hist <- .GlobalEnv$.ShinyGR.hist[!(duplicated(sapply(.GlobalEnv$.ShinyGR.hist, function(x) sum(x$Param)), fromLast = TRUE) & 
-                                                             duplicated(sapply(.GlobalEnv$.ShinyGR.hist, function(x) x$TypeModel ), fromLast = TRUE))]
+                                                             duplicated(sapply(.GlobalEnv$.ShinyGR.hist, function(x) x$TypeModel), fromLast = TRUE))]
     .GlobalEnv$.ShinyGR.hist <- tail(.GlobalEnv$.ShinyGR.hist, n = 2)
     if (length(.GlobalEnv$.ShinyGR.hist) == 2 &  is.null(names(.GlobalEnv$.ShinyGR.hist[[1]]))) {
       .GlobalEnv$.ShinyGR.hist[[1]] <- NULL
     }
     if (length(.GlobalEnv$.ShinyGR.hist) == 2 & !is.null(names(.GlobalEnv$.ShinyGR.hist[[1]]))) {
-      if (length(.GlobalEnv$.ShinyGR.hist[[1]]$Qsim) != length(.GlobalEnv$.ShinyGR.hist[[2]]$Qsim)) {
+      if (length(.GlobalEnv$.ShinyGR.hist[[1]]$Qsim) != length(.GlobalEnv$.ShinyGR.hist[[2]]$Qsim) |
+          sum(.GlobalEnv$.ShinyGR.hist[[1]]$Crit$Value) != sum(.GlobalEnv$.ShinyGR.hist[[2]]$Crit$Value)) {
         OBSold <- getPrep()$OBS
         OBSold$TypeModel <- .GlobalEnv$.ShinyGR.hist[[1]]$TypeModel
-        if (.TypeModelGR(OBSold)$CemaNeige & !.TypeModelGR(getPrep()$OBS)$CemaNeige) { # present: No CemaNeige ; old: CemaNeige
+        if (.TypeModelGR(OBSold)$CemaNeige & !.TypeModelGR(getPrep()$OBS)$CemaNeige | # present: No CemaNeige ; old: CemaNeige
+            sum(.GlobalEnv$.ShinyGR.hist[[1]]$Crit$Value) != sum(.GlobalEnv$.ShinyGR.hist[[2]]$Crit$Value)) { 
           if (input$Dataset == "Unnamed watershed") {
             ObsBV <- NULL
           } else {
@@ -420,7 +421,6 @@ shinyServer(function(input, output, session) {
   
   ## Target date slider
   observeEvent({input$Dataset}, {
-    print(.ShinyGR.args$SimPer[[input$Dataset]])
     updateSliderInput(session, inputId = "Period",
                       min = as.POSIXct(.ShinyGR.args$SimPer[[input$Dataset]][1L], tz = "UTC"),
                       max = as.POSIXct(.ShinyGR.args$SimPer[[input$Dataset]][2L], tz = "UTC"),
-- 
GitLab