app_server.R 5.32 KB
Newer Older
Virgile Baudrot's avatar
Virgile Baudrot committed
1
#' @import shiny
Virgile Baudrot's avatar
up    
Virgile Baudrot committed
2
#' @import shinyWidgets
Virgile Baudrot's avatar
Virgile Baudrot committed
3
4
5
6
7
8
9
10
11
12
#' @import briskaR
#' @import rgdal
#' @import sf
#' @import dplyr
#' @import tidyr
#' @import readr
#' 
#' 
app_server <- function(input, output,session) {
  
Virgile Baudrot's avatar
Virgile Baudrot committed
13
14
  r <- reactiveValues()
  # List the first level callModules here
Virgile Baudrot's avatar
Virgile Baudrot committed
15
  ##################
Virgile Baudrot's avatar
Virgile Baudrot committed
16
  ## START
Virgile Baudrot's avatar
Virgile Baudrot committed
17
  ##################
18
19
20
21
  # TRANSITION
  observeEvent(input$switchLandscapeTab, {
    newtab <- switch(input$tabs,
                     "start" = "landscape")
Virgile Baudrot's avatar
Virgile Baudrot committed
22
    shinydashboard::updateTabItems(session, "tabs", newtab)
23
  })
Virgile Baudrot's avatar
Virgile Baudrot committed
24
  callModule(mod_tabItemStart_server, id="tabItemStart_ui_1", session = session, r=r)
Virgile Baudrot's avatar
Virgile Baudrot committed
25
  ##################
Virgile Baudrot's avatar
Virgile Baudrot committed
26
  ## LANDSCAPE
Virgile Baudrot's avatar
Virgile Baudrot committed
27
  ##################
28
29
30
31
  #  TRANSITION
  observeEvent(input$switchDispersalTab, {
    newtab <- switch(input$tabs,
                     "landscape" = "dispersal")
Virgile Baudrot's avatar
Virgile Baudrot committed
32
    shinydashboard::updateTabItems(session, "tabs", newtab)
33
  })
Virgile Baudrot's avatar
Virgile Baudrot committed
34
  ## OBSERVE
Virgile Baudrot's avatar
Virgile Baudrot committed
35
  observe({
Virgile Baudrot's avatar
Virgile Baudrot committed
36
    r$landscapeSOURCE <- sf::st_zm(sf::st_read(req(input$landscapeSOURCE)$datapath))
Virgile Baudrot's avatar
Virgile Baudrot committed
37
38
  })
  observe({
Virgile Baudrot's avatar
Virgile Baudrot committed
39
    r$landscapeHOST <- sf::st_zm(sf::st_read(req(input$landscapeHOST)$datapath))
Virgile Baudrot's avatar
Virgile Baudrot committed
40
41
  })
  observe({
Virgile Baudrot's avatar
Virgile Baudrot committed
42
    r$landscapeSQUAREFRAME <- sf::st_zm(sf::st_read(req(input$landscapeSQUAREFRAME)$datapath))
Virgile Baudrot's avatar
Virgile Baudrot committed
43
44
  })
  callModule(mod_tabItemLandscape_server, id="tabItemLandscape_ui_1", session = session, r=r)
Virgile Baudrot's avatar
Virgile Baudrot committed
45
  ##################
Virgile Baudrot's avatar
Virgile Baudrot committed
46
  ## DISPERSAL
Virgile Baudrot's avatar
Virgile Baudrot committed
47
  ##################
48
49
50
51
  # TRANSITION
  observeEvent(input$switchEmissionTab, {
    newtab <- switch(input$tabs,
                     "dispersal" = "emission")
Virgile Baudrot's avatar
Virgile Baudrot committed
52
    shinydashboard::updateTabItems(session, "tabs", newtab)
53
  })
Virgile Baudrot's avatar
Virgile Baudrot committed
54
  callModule(mod_tabItemDispersal_server, id="tabItemDispersal_ui_1", session = session, r=r)
Virgile Baudrot's avatar
Virgile Baudrot committed
55
  ##################
Virgile Baudrot's avatar
Virgile Baudrot committed
56
  ## EMISSION
Virgile Baudrot's avatar
Virgile Baudrot committed
57
  ##################
58
59
60
61
62
63
  # TRANSITION
  observeEvent(input$switchHostTab, {
    newtab <- switch(input$tabs,
                     "emission" = "host")
    updateTabItems(session, "tabs", newtab)
  })
Virgile Baudrot's avatar
Virgile Baudrot committed
64
65
66
67
68
69
70
  observe({
    r$sourceEMISSION <- read.csv(file = req(input$sourceEMISSION)$datapath,
                                 header = input$headerEMISSION,
                                 sep = input$sepEMISSION,
                                 quote = input$quoteEMISSION)
  })
  callModule(mod_tabItemEmission_server, "tabItemEmission_ui_1", session = session, r=r)
Virgile Baudrot's avatar
Virgile Baudrot committed
71
72
73
  ##################
  ## HOST
  ##################
74
75
76
77
  # TRANSITION
  observeEvent(input$switchDevelopmentTab, {
    newtab <- switch(input$tabs,
                     "host" = "development")
Virgile Baudrot's avatar
Virgile Baudrot committed
78
    shinydashboard::updateTabItems(session, "tabs", newtab)
79
  })
Virgile Baudrot's avatar
Virgile Baudrot committed
80
81
82
83
84
85
86
87
88
89
90
91
  observe({
    r$dateEMERGENCE <- read.csv(file = req(input$dateEMERGENCE)$datapath,
                                header = input$headerEMERGENCE,
                                sep = input$sepEMERGENCE,
                                quote = input$quoteEMERGENCE)
  })
  observe({
    r$timeTEMPERATURE <- read.csv(file = req(input$timeTEMPERATURE)$datapath,
                                header = input$headerTEMPERATURE,
                                sep = input$sepTEMPERATURE,
                                quote = input$quoteTEMPERATURE)
  })
Virgile Baudrot's avatar
Virgile Baudrot committed
92
93
94
95
  observe({
    r$individualSITE <- sf::st_read(req(input$individualSITE)$datapath) %>%
      dplyr::mutate(DateEmergence = as.Date(Date, origin = input$originDateEMERGENCE))
  })
Virgile Baudrot's avatar
Virgile Baudrot committed
96
97
98
99
  callModule(mod_tabItemHost_server, "tabItemHost_ui_1", session = session, r=r)
  ##################
  ## DEVELOPMENT
  ##################
100
101
102
103
  # TRANSITION
  observeEvent(input$switchExposureTab, {
    newtab <- switch(input$tabs,
                     "development" = "exposure")
Virgile Baudrot's avatar
Virgile Baudrot committed
104
    shinydashboard::updateTabItems(session, "tabs", newtab)
105
  })
Virgile Baudrot's avatar
Virgile Baudrot committed
106
107
108
109
  callModule(mod_tabItemDevelopment_server, "tabItemDevelopment_ui_1", session = session, r=r)
  ##################
  ## EXPOSURE
  ##################
Virgile Baudrot's avatar
Virgile Baudrot committed
110
111
112
113
114
115
  # TRANSITION
  observeEvent(input$switchDamageTab, {
    newtab <- switch(input$tabs,
                     "exposure" = "damage")
    shinydashboard::updateTabItems(session, "tabs", newtab)
  })
Virgile Baudrot's avatar
Virgile Baudrot committed
116
117
118
119
  callModule(mod_tabItemExposure_server, "tabItemExposure_ui_1", session = session, r=r)
  ##################
  ## DAMAGE
  ##################
Virgile Baudrot's avatar
Virgile Baudrot committed
120
121
122
  # TRANSITION
  observeEvent(input$switchInteractiveMapTab, {
    newtab <- switch(input$tabs,
Virgile Baudrot's avatar
Virgile Baudrot committed
123
                     "damage" = "interactiveMap")
Virgile Baudrot's avatar
Virgile Baudrot committed
124
125
    shinydashboard::updateTabItems(session, "tabs", newtab)
  })
Virgile Baudrot's avatar
Virgile Baudrot committed
126
  callModule(mod_tabItemDamage_server, "tabItemDamage_ui_1", session = session, r=r)
Virgile Baudrot's avatar
Virgile Baudrot committed
127
128
129
130
131
132
  ##################
  ## INTERACTIVE MAP
  ##################
  # TRANSITION
  observeEvent(input$switchDataExplorerTab, {
    newtab <- switch(input$tabs,
Virgile Baudrot's avatar
Virgile Baudrot committed
133
                     "interactiveMap" = "report")
Virgile Baudrot's avatar
Virgile Baudrot committed
134
135
136
    shinydashboard::updateTabItems(session, "tabs", newtab)
  })
  callModule(mod_tabItemInteractiveMap_server, "tabItemInteractiveMap_ui_1", session = session, r=r)
Virgile Baudrot's avatar
Virgile Baudrot committed
137
138
139
  ##################
  ## DATA EXPLORER
  ##################
Virgile Baudrot's avatar
Virgile Baudrot committed
140
141
142
143
144
145
146
  # # TRANSITION
  # observeEvent(input$switchReport, {
  #   newtab <- switch(input$tabs,
  #                    "dataExplorer" = "report")
  #   shinydashboard::updateTabItems(session, "tabs", newtab)
  # })
  # callModule(mod_tabItemDataExplorer_server, "tabItemDataExplorer_ui_1", session = session, r=r)
Virgile Baudrot's avatar
Virgile Baudrot committed
147
148
149
  ##################
  ## REPORT
  ##################
Virgile Baudrot's avatar
Virgile Baudrot committed
150
151
152
153
154
155
  # TRANSITION
  observeEvent(input$switchCongratHome, {
    newtab <- switch(input$tabs,
                     "report" = "start")
    shinydashboard::updateTabItems(session, "tabs", newtab)
  })
Virgile Baudrot's avatar
Virgile Baudrot committed
156
  callModule(mod_tabItemReport_server, "tabItemReport_ui_1", session = session, r=r)
157

Virgile Baudrot's avatar
Virgile Baudrot committed
158
}