server.R 2.47 KB
Newer Older
unknown's avatar
unknown committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# server.R

shinyServer(function(input,  output) {

    
  output$myPlot <- renderPlot({

    Param <- c(input$X1, input$X2, input$X3, input$X4)
    
    # SIM <- SimGR(ObsGR = ObsGR, Param = Param, WupPer = WupPer, SimPer = SimPer)
    SIM <- SimGR(ObsGR = .SimGR4J.args$ObsGR, Param = Param, WupPer = .SimGR4J.args$WupPer, SimPer = .SimGR4J.args$SimPer)
    
    OutputsModel <- SIM$OutputsModel
    RunOptions   <- SIM$OptionsSimul
    
    getplotType <- reactive({
        switch(input$plotType, 
           "time series"  =  1, 
           "synthesis"    =  2)#, 
           # "user-defined" =  3)
    })
    
    LLL <- length(OutputsModel$Qsim)
    PosInd <- round(input$WindowPosition*LLL)
    WinInd <- round(input$WindowFraction*LLL)
    WinInd <- ifelse(WinInd < 2, 2, WinInd)
    # if (WinInd < 2) {
    #   WinInd <- 2
    # }
    IndStart  <- PosInd - ((WinInd-1) %/% 2 + (WinInd-1) %% 2)
    IndStart2 <- IndStart
    IndStop   <- PosInd + ((WinInd-1) %/% 2)
    IndStop2  <- IndStop 
    if (IndStart < 1) {
      IndStart2 <- 1
      IndStop2  <- IndStop +diff(c(IndStart,  1))
    }
    if (IndStop > LLL) {
      IndStop2  <- LLL
      IndStart2 <- IndStart-diff(c(LLL, IndStop))
    }
    IndPlot <- seq(from = IndStart2, to = IndStop2, by = 1)
    
    if (getplotType() == 1) {
      par(mfrow = c(1, 1))#SIM$Qobs[RunOptions$IndPeriod_Run][IndPlot]
      plot(OutputsModel$DatesR[IndPlot], SIM$Qobs[IndPlot], type = "l", lwd = 1, col = "black", xlab = "", ylab = "Q [mm/d]") 
      lines(OutputsModel$DatesR[IndPlot], OutputsModel$Qsim[IndPlot], lwd = 1, col = "red") 
      legend("topright", bty = "n", c("obs.", "sim."), col = c("black", "red"), lwd = 2)
      mtext(side = 3, line = 1, paste("Period ", format(OutputsModel$DatesR[IndPlot[1]], "%d/%m/%Y"), " - ", format(OutputsModel$DatesR[tail(IndPlot, 1)], "%d/%m/%Y"), sep = ""))
    }
    if (getplotType() == 2) {
      plot_OutputsModel(OutputsModel = OutputsModel, Qobs = SIM$Qobs, IndPeriod_Plot = IndPlot)
    }
    # if (getplotType() == 3) {
    #   Tmp <- FALSE
      # if (exists("plot_UserDefined")) {
      #   if (is.function(plot_UserDefined)) {
      #     Tmp <- TRUE
      #   }
      # }
      # if (Tmp) { 
      #   plot_UserDefined(OutputsModel, IndPlot) 
      # } else { 
        # par(mfrow = c(1, 1))
        # plot(c(-10, +10), c(-10, +10), type = "n", xlab = "", ylab = "", xaxt = "n", yaxt = "n")
        # text(0, 0, "Error: the function 'plot_UserDefined' has not been defined") 
      # }
    # }
        

  })

})