]> nmode's Git Repositories - Rnaught/blob - R/ui.R
Refactor WP
[Rnaught] / R / ui.R
1 ui <- function() {
2 shiny::fluidPage(
3 # Title.
4 shiny::titlePanel(shiny::HTML(
5 paste0("Rnaught: An Estimation Suite for R", shiny::tags$sub("0")))),
6 # Sidebar layout.
7 shiny::sidebarLayout(
8 # Sidebar. Hidden if the 'About' tab is selected.
9 shiny::conditionalPanel(condition = "input.tabset != 'About'",
10 shiny::sidebarPanel(id = "sidebar", data_sidebar(), est_sidebar())),
11 # Main panel.
12 shiny::mainPanel(id = "main",
13 shiny::tabsetPanel(id = "tabset", type = "tabs",
14 shiny::tabPanel("About", shiny::br(), "Hello"),
15 shiny::tabPanel("Data", shiny::br(),
16 shiny::dataTableOutput(outputId = "dataTable"),
17 shiny::tags$style(type = "text/css",
18 "#dataTable tfoot { display:none; }")),
19 shiny::tabPanel("Estimators", shiny::br(),
20 shiny::dataTableOutput(outputId = "estTable"),
21 shiny::tags$style(type = "text/css",
22 "#estTable tfoot { display:none; }"),
23 shiny::downloadButton(outputId = "downloadEst",
24 label = "Download table as .csv"))
25 )
26 )
27 )
28 )
29 }
30
31 # Data tab sidebar.
32 data_sidebar <- function() {
33 shiny::conditionalPanel(condition = "input.tabset == 'Data'",
34 shiny::h3("Enter data"),
35 # Data input method selection.
36 shiny::radioButtons(inputId = "dataInputMethod", label = "",
37 choices=list("Manually" = 1, "Upload a .csv file" = 2,
38 "Paste a .csv file" = 3)),
39 # Option 1: Manual entry.
40 shiny::conditionalPanel(condition = "input.dataInputMethod == '1'",
41 shiny::textInput(inputId = "dataName", label = "Dataset name"),
42 shiny::span(shiny::textOutput(outputId = "dataNameWarn"),
43 style = "color: red;"),
44 shiny::fluidRow(
45 shiny::column(8,
46 shiny::textInput(inputId = "dataCounts",
47 label = help_tool("Case counts", paste0("Enter as a ",
48 "comma-separated list of positive integers, with at least two ",
49 "entries. (Example: 1,1,2,3,5,8)")))),
50 shiny::column(4, shiny::selectInput(inputId = "dataUnits",
51 label = "Reporting frequency", choices = list("Daily", "Weekly")))
52 ),
53 shiny::span(shiny::textOutput(outputId = "dataCountsWarn"),
54 style = "color: red;")
55 ),
56 # Option 2: Upload .csv file.
57 shiny::conditionalPanel(condition = "input.dataInputMethod == '2'",
58 shiny::fileInput(inputId = "dataUpload", label = "",
59 accept = c("text/csv", "text/comma-separated-values,text/plain",
60 ".csv")),
61 ),
62 # Option 3: Paste .csv file.
63 shiny::conditionalPanel(condition = "input.dataInputMethod == '3'",
64 shiny::textAreaInput(inputId = "dataPaste", label = "",
65 rows = 8, resize = "none"),
66 ),
67 # Warning text for .csv upload / paste.
68 shiny::conditionalPanel(
69 condition = "['2', '3'].includes(input.dataInputMethod)",
70 shiny::span(shiny::textOutput(outputId = "dataCSVWarn"),
71 style = "color: red;"),
72 ),
73 # Button to add data.
74 shiny::actionButton(inputId = "addData", label = "Add")
75 )
76 }
77
78 # Estimators tab sidebar.
79 est_sidebar <- function() {
80 shiny::conditionalPanel(condition = "input.tabset == 'Estimators'",
81 shiny::h3("Estimators"),
82 WP_collapse(),
83 seqB_collapse(),
84 ID_collapse(),
85 IDEA_collapse(),
86
87 shiny::tags$style(type = "text/css",
88 "summary { display: list-item; cursor: pointer; }"),
89 shiny::tags$style(type = "text/css", "summary h4 { display: inline; }")
90 )
91 }
92
93 # Collapsable entry for White & Pagano (WP) method.
94 WP_collapse <- function() {
95 shiny::tags$details(
96 shiny::tags$summary(shiny::h4("White & Pagano (WP)")),
97 shiny::p("Method due to White and Pagano (2008), assumes a branching process
98 based model. Serial distribution can be assumed known or can be
99 estimated using maximum likelihood; When serial interval is
100 unknown the method takes longer to compute, though is still
101 real-time."),
102 shiny::br(),
103 shiny::radioButtons(inputId = "serialWPKnown",
104 label = "Is the mean serial interval known?",
105 inline = TRUE, choices = list("Yes" = 1, "No" = 2)),
106 # Known serial interval.
107 shiny::conditionalPanel(condition = "input.serialWPKnown == '1'",
108 serial_fields("WP")),
109 # Unknown serial interval.
110 shiny::conditionalPanel(condition = "input.serialWPKnown == '2'",
111 shiny::h5("Grid Search Parameters"),
112 shiny::fluidRow(
113 shiny::column(4, shiny::textInput(inputId = "gridLengthInput",
114 label = "Grid length", value = "100")),
115 shiny::column(4, shiny::textInput(inputId = "gridShapeInput",
116 label = "Max. shape", value = "10")),
117 shiny::column(4, shiny::textInput(inputId = "gridScaleInput",
118 label = "Max. scale", value = "10"))
119 ),
120 shiny::fluidRow(
121 shiny::column(4, shiny::span(shiny::textOutput(
122 outputId = "gridLengthWarn"), style = "color: red;")),
123 shiny::column(4, shiny::span(shiny::textOutput(
124 outputId = "gridShapeWarn"), style = "color: red;")),
125 shiny::column(4, shiny::span(shiny::textOutput(
126 outputId = "gridScaleWarn"), style = "color: red;"))
127 )
128 ),
129 shiny::actionButton(inputId = "addWP", label = "Add")
130 )
131 }
132
133 # Collapsable entry for Sequential Bayes (seqB) method.
134 seqB_collapse <- function() {
135 shiny::tags$details(
136 shiny::tags$summary(shiny::h4("Sequential Bayes (seqB)")),
137 shiny::p("This is a description of the method."),
138 shiny::br(),
139 serial_fields("seqB"),
140 shiny::textInput(inputId = "kappaInput",
141 label = help_tool("Maximum value", paste0("This describes the prior ",
142 "belief of R0, and should be set to a higher value if R0 is believed ",
143 "be larger. (Default: 20)")), value = "20"),
144 shiny::span(shiny::textOutput(outputId = "kappaWarn"),
145 style = "color: red;"),
146 shiny::actionButton(inputId = "addseqB", label = "Add")
147 )
148 }
149
150 # Collapsable entry for Incidence Decay (ID) method.
151 ID_collapse <- function() {
152 shiny::tags$details(
153 shiny::tags$summary(shiny::h4("Incidence Decay (ID)")),
154 shiny::p("This is a description of the method."),
155 shiny::br(),
156 serial_fields("ID"),
157 shiny::actionButton(inputId = "addID", label = "Add")
158 )
159 }
160
161 # Collapsable entry for Incidence Decay & Exponential Adjustment (IDEA) method.
162 IDEA_collapse <- function() {
163 shiny::tags$details(
164 shiny::tags$summary(
165 shiny::h4("Incidence Decay and Exponential Adjustment (IDEA)")),
166 shiny::p("This is a description of the method."),
167 shiny::br(),
168 serial_fields("IDEA"),
169 shiny::actionButton(inputId = "addIDEA", label = "Add")
170 )
171 }
172
173 # Input fields and warning text for the mean serial interval.
174 serial_fields <- function(method) {
175 shiny::HTML(paste0(
176 shiny::fluidRow(
177 shiny::column(8, shiny::textInput(
178 inputId = paste0("serial", method, "Input"),
179 label = "Mean Serial Interval")),
180 shiny::column(4, shiny::selectInput(
181 inputId = paste0("serial", method, "Units"),
182 label = "Time units", choices = list("Days", "Weeks")))
183 ),
184 shiny::span(shiny::textOutput(outputId = paste0("serial", method, "Warn")),
185 style = "color: red;")
186 ))
187 }
188
189 # Display help information on hover.
190 help_tool <- function(label, help_text) {
191 shiny::HTML(paste0(label, shiny::tags$sup("[?]", title = help_text)))
192 }