server.R 6.74 KB
Newer Older
1
2
# DQAgui - A graphical user interface (GUI) to the functions implemented in the
# R package 'DQAstats'.
Jonathan Mang's avatar
Jonathan Mang committed
3
# Copyright (C) 2019-2020 Universitätsklinikum Erlangen
Lorenz Kapsner's avatar
Lorenz Kapsner committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

kapsner's avatar
kapsner committed
18
19
20
21
shiny::shinyServer(function(input, output, session) {
    # define reactive values here
    rv <- shiny::reactiveValues()

22
23
24
    # set headless
    rv$headless <- FALSE

Jonathan Mang's avatar
Jonathan Mang committed
25
    # set utils_path
26
    rv$utilspath <- DQAstats::clean_path_name(utils_path)
27

28
    # read datamap email
29
30
31
32
    rv$datamap_email <- tryCatch(
        expr = {
            # if existing, set email address for data-map button
            out <- DQAstats::get_config(
Lorenz Kapsner's avatar
Lorenz Kapsner committed
33
                config_file = paste0(utils_path, "/MISC/email.yml"),
34
35
36
37
38
39
40
41
42
                config_key = "email"
            )
        }, error = function(e) {
            print(e)
            # otherwise set it to empty string
            out <- ""
        }, finally = function(f) {
            return(out)
        })
43

44
45
46
    # current date
    rv$current_date <- format(Sys.Date(), "%d. %B %Y", tz = "CET")

47
48
    # run on_start here
    on_start(session, rv, input, output)
kapsner's avatar
kapsner committed
49
50
51
52
53
54

    # handle reset
    shiny::observeEvent(input$reset, {
        shinyjs::js$reset()
    })

55
56
57
58
    input_reactive <- reactive({
        input
    })

kapsner's avatar
kapsner committed
59
60
61
62
    # ########################
    # # tab_config
    # ########################

63
    shiny::callModule(module_config2_server,
64
65
66
                      "moduleConfig",
                      rv,
                      input_re = input_reactive)
kapsner's avatar
kapsner committed
67
68

    shiny::observe({
69
70
71
72
        # first call (rv$target_getdata = TRUE and rv$source_getdata = TRUE),
        # when load-data-button quality checks in moduleDashboard are passed
        if (!is.null(rv$getdata_target) &&
            !is.null(rv$getdata_source)) {
kapsner's avatar
kapsner committed
73
            # hide load data button
74
            shinyjs::hide("moduleConfig-dash_load_btn")
kapsner's avatar
kapsner committed
75
76
77
78
79
80
81

            rv$start <- TRUE
        }
    })

    shiny::observe({
        req(rv$mdr)
82
83
        shinyjs::disable("moduleConfig-config_load_mdr")

kapsner's avatar
kapsner committed
84
        output$mdr <- shinydashboard::renderMenu({
85
86
87
88
89
            shinydashboard::sidebarMenu(shinydashboard::menuItem(
                "DQ MDR",
                tabName = "tab_mdr",
                icon = icon("database")
            ))
kapsner's avatar
kapsner committed
90
        })
91
92
93
94
95
        shinydashboard::updateTabItems(
            session = session,
            inputId = "tabs",
            selected = "tab_config"
        )
kapsner's avatar
kapsner committed
96
97
98
99
100
    })

    shiny::observe({
        shiny::req(rv$report_created)

101
102
        # set end_time
        rv$end_time <- format(Sys.time(), usetz = T, tz = "CET")
kapsner's avatar
kapsner committed
103
        # calc time-diff
104
105
        rv$duration <-
            difftime(rv$end_time, rv$start_time, units = "mins")
kapsner's avatar
kapsner committed
106
107
108
109

        # render menu
        output$menu <- shinydashboard::renderMenu({
            shinydashboard::sidebarMenu(
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
                #shinydashboard::menuItem("Review raw data",
                #tabName = "tab_rawdata1", icon = icon("table")),
                shinydashboard::menuItem(
                    text = "Descriptive Results",
                    tabName = "tab_descriptive",
                    icon = icon("table")
                ),
                shinydashboard::menuItem(
                    text = "Plausibility Checks",
                    tabName = "tab_plausibility",
                    icon = icon("check-circle"),
                    shinydashboard::menuSubItem(
                        text = "Atemporal Plausibility",
                        tabName = "tab_atemp_plausibility"
                    ),
                    shinydashboard::menuSubItem(
                        text = "Uniqueness Plausibility",
                        tabName = "tab_uniq_plausibility"
                    )
                ),
                shinydashboard::menuItem(
                    text = "Completeness",
                    tabName = "tab_completeness",
                    icon = icon("chart-line")
                ),
                #shinydashboard::menuItem("Visualizations",
                #tabName = "tab_visualizations",
                #icon = icon("chart-line")),
                shinydashboard::menuItem(
                    text = "Reporting",
                    tabName = "tab_report",
                    icon = icon("file-alt")
                )
kapsner's avatar
kapsner committed
143
144
            )
        })
145
146
147
148
149
        shinydashboard::updateTabItems(
            session = session,
            inputId = "tabs",
            selected = "tab_dashboard"
        )
kapsner's avatar
kapsner committed
150
151
152
153
154
    })

    ########################
    # tab_dashboard
    ########################
155
156
157
158
    shiny::callModule(module_dashboard_server,
                      "moduleDashboard",
                      rv,
                      input_re = input_reactive)
kapsner's avatar
kapsner committed
159
160
161
162

    ########################
    # tab_descriptive
    ########################
163
164
165
166
    shiny::callModule(module_descriptive_server,
                      "moduleDescriptive",
                      rv,
                      input_re = input_reactive)
kapsner's avatar
kapsner committed
167
168
169
170

    ########################
    # tab_plausibility
    ########################
171
172
173
174
175
176
177
178
    shiny::callModule(module_atemp_pl_server,
                      "moduleAtempPlausibility",
                      rv,
                      input_re = input_reactive)
    shiny::callModule(module_uniq_plaus_server,
                      "moduleUniquePlausibility",
                      rv,
                      input_re = input_reactive)
kapsner's avatar
kapsner committed
179
180

    ########################
181
    # tab_completeness
kapsner's avatar
kapsner committed
182
    ########################
183
184
185
186
    shiny::callModule(module_completeness_server,
                      "moduleCompleteness",
                      rv,
                      input_re = input_reactive)
187
188
189
190

    # ########################
    # # tab_visualization
    # ########################
191
192
193
194
    #% shiny::callModule(module_visualizations_server,
    #%                   "moduleVisulizations",
    #%                   rv,
    #%                   input_re = input_reactive)
kapsner's avatar
kapsner committed
195
196
197
198

    ########################
    # tab_report
    ########################
199
200
201
202
    shiny::callModule(module_report_server,
                      "moduleReport",
                      rv,
                      input_re = input_reactive)
kapsner's avatar
kapsner committed
203
204
205
206

    ########################
    # tab_mdr
    ########################
207
208
209
210
    shiny::callModule(module_mdr_server,
                      "moduleMDR",
                      rv,
                      input_re = input_reactive)
kapsner's avatar
kapsner committed
211
212

})