-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
175 lines (157 loc) · 5.65 KB
/
app.R
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
isLocalRun <- FALSE
users <- reactiveValues(count = 0)
# Allow uploading files up to 70MB in size
options(shiny.maxRequestSize = 70 * 1024^2)
# Load standard libraries
suppressPackageStartupMessages(library(data.table))
suppressPackageStartupMessages(library(DT))
suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(shiny))
suppressPackageStartupMessages(library(shinydashboard))
suppressPackageStartupMessages(library(shinycssloaders))
# Load main library
library(hivEstimatesAccuracy)
# Load application modules
modulesPath <- system.file("shiny/modules", package = "hivEstimatesAccuracy")
wwwPath <- system.file("shiny/www", package = "hivEstimatesAccuracy")
source(file.path(modulesPath, "inputDataUpload.R"))
source(file.path(modulesPath, "dataSummary.R"))
source(file.path(modulesPath, "dataAdjust.R"))
source(file.path(modulesPath, "createReports.R"))
source(file.path(modulesPath, "outputs.R"))
source(file.path(modulesPath, "manual.R"))
source(file.path(modulesPath, "hivModel.R"))
addResourcePath("www", wwwPath)
# App globals
titleString <- "HIV Estimates Accuracy"
version <- as.character(packageDescription(pkg = "hivEstimatesAccuracy", fields = "Version"))
# Define application user interface
ui <- tagList(
shinyjs::useShinyjs(),
dashboardPage(
tags$header(
class = "main-header",
span(class = "logo", titleString),
tags$nav(
class = "navbar navbar-static-top",
div(class = "navbar-custom-menu",
div(sprintf("v. %s", version)),
textOutput("userCount"),
div(tags$a(href = "./", target = "_blank", list(icon("external-link"), "Open new instance in separate tab"))),
actionLink("setSeed", "Set seed", icon = icon("random"))
)
)
),
dashboardSidebar(
sidebarMenu(
menuItem("Input data upload", tabName = "upload", icon = icon("upload")),
menuItem("Input data summary", tabName = "summary", icon = icon("bar-chart")),
menuItem("Adjustments", tabName = "adjustments", icon = icon("bolt")),
menuItem("HIV Modelling", tabName = "hivModel", icon = icon("calculator")),
menuItem("Reports", tabName = "reports", icon = icon("book")),
menuItem("Outputs", tabName = "outputs", icon = icon("download")),
menuItem("Manual", tabName = "manual", icon = icon("book"))
),
width = 180
),
dashboardBody(
tags$head(
tags$script(async = NA, src = "https://www.googletagmanager.com/gtag/js?id=UA-125099925-2"),
includeScript(path = file.path(wwwPath, "/js/google_analytics.js")),
tags$link(rel = "stylesheet", type = "text/css", href = "./www/css/style.css"),
tags$title("HIV Estimates Accuracy")
),
tabItems(
tabItem(tabName = "upload", fluidRow(inputDataUploadUI("upload"))),
tabItem(tabName = "summary", fluidRow(dataSummaryUI("summary"))),
tabItem(tabName = "adjustments", fluidRow(dataAdjustUI("adjustments"))),
tabItem(tabName = "hivModel", fluidRow(hivModelUI("hivModel"))),
tabItem(tabName = "reports", fluidRow(createReportsUI("reports"))),
tabItem(tabName = "outputs", fluidRow(outputsUI("outputs"))),
tabItem(tabName = "manual", fluidRow(manualUI("manual")))
)
)
)
)
# Define application server logic
server <- function(input, output, session)
{
appStatus <- reactiveValues(
CreateTime = Sys.time(),
Version = version,
Seed = NULL,
FileName = "",
StateUploading = FALSE,
InputDataUploaded = FALSE,
OriginalData = NULL,
DefaultValues = list(),
OriginalDataAttrs = c(),
AttrMapping = list(),
AttrMappingStatus = NULL,
AttrMappingValid = FALSE,
InputDataTest = NULL,
InputDataTestStatus = NULL,
DiagYearRange = NULL,
DiagYearRangeApply = FALSE,
NotifQuarterRange = NULL,
NotifQuarterRangeApply = NULL,
InputData = NULL,
AdjustedData = NULL,
HIVModelData = NULL,
AdjustmentSpecs = adjustmentSpecs,
MIAdjustmentName = "None",
RDAdjustmentName = "None",
RunLog = "",
IntermReport = "",
Report = ""
)
callModule(inputDataUpload, "upload", appStatus)
callModule(dataSummary, "summary", appStatus)
callModule(dataAdjust, "adjustments", appStatus)
callModule(createReports, "reports", appStatus)
callModule(outputs, "outputs", appStatus)
callModule(hivModel, "hivModel", appStatus)
callModule(manual, "manual")
observeEvent(input[["setSeed"]], {
showModal(
modalDialog(
title = "Set seed",
textInput("seed", label = "Seed value", value = appStatus$Seed),
p("Give empty value or type 'default' to remove fixed seed"),
footer = tagList(
actionButton("seedDlgOk", "OK",
style = "background-color: #69b023; color: white"),
modalButton("Cancel")
),
size = "s"
)
)
})
observeEvent(input[["seedDlgOk"]], {
seed <- input$seed
if (seed == "" || tolower(seed) == "default") {
appStatus$Seed <- NULL
} else {
appStatus$Seed <- seed
}
removeModal()
})
onSessionStart <- isolate({
users$count <- users$count + 1
})
onSessionEnded(function() {
isolate({
users$count <- users$count - 1
if (isLocalRun && users$count == 0) {
stopApp()
}
})
})
output[["userCount"]] <- renderText({
sprintf("Number of open instances: %d", users$count)
})
}
# Run application
shinyApp(ui, server,
options = c(display.mode = "normal",
test.mode = FALSE))