-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.R
131 lines (110 loc) · 4.06 KB
/
ui.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
###################
## ui Shiny file ##
###################
# Load necessary packages
load_packages <- Vectorize(function(package) {
# Check if package is installed, suppress warning message (only logical T/F)
condition <- suppressWarnings(!require(package, character.only = T))
# Install if not installed yet
if (condition)
install.packages(package, dep = T)
# Load
require(package, character.only = T)
})
packages <- c("shiny", "shinydashboard", "plotly",
"shinyWidgets", "tidyverse", "deSolve")
load_packages(packages)
# Customise sidebar
sidebar <- dashboardSidebar(
width = 340,
# Read description of app or run directly
# icons from https://fontawesome.com
sidebarMenu(id = "nav",
menuItem("Information", tabName = "app_descrip",
icon = icon("info")),
menuItem("Simulation", tabName = "sims",
icon = icon("arrow-circle-right"))
),
# Pick compartmental model
conditionalPanel(
condition = 'input.nav == "sims"',
selectInput("type", "Model:", list(SI = "SI",
SIS = "SIS",
SIR = "SIR")),
# Add transmission param and alpha for interevent times
sliderInput('beta', "Beta (per year)", value = 36.5,
min = 0, max = 50, step = 0.1),
sliderInput('alpha', "Shape of Gamma distribution \n
of interevent times", value = 1, # exponential by default
min = 0, max = 5, step = 0.01),
# For SIS & SIR, add recovery
conditionalPanel(
condition = 'input.type == "SIS" || input.type == "SIR"',
sliderInput('gamma', "Average infectious period (days)", value = 50,
min = 0, max = 365, step = 1)
),
hr(),
# Button to run based on inputs
actionButton("run", "Run"),
h5("Initial conditions:", style="padding:15px;"),
splitLayout(
cellWidths = c("29%", "29%", "29%"),
numericInput('N', "N", value = 200, min = 0, max = 1000),
numericInput('S', "S", value = 199, min = 0, max = 1000),
numericInput('I', "I", value = 1, min = 0, max = 1000)
),
numericInput('t_end', "Time frame (days) ",
value = 360, min = 0, max = 365) # Two months
)
)
# Customise body
body <- dashboardBody(
tabItems(
tabItem(tabName = "sims",
fluidRow(
tabBox(
width = 12,
tabPanel(title = "Trajectories",
plotlyOutput("plot_descrip"),
height = 7, width = 9),
tabPanel(title = "Event rates",
plotlyOutput("plot_rates"),
height = 7, width = 9),
tabPanel(title = "Deterministic",
plotlyOutput("plot_determ"),
height = 7, width = 9),
tabPanel(title = "Interevent vs. # Infectious",
plotlyOutput("interev_vs_I"),
height = 7, width = 9),
tabPanel(title = "Distribution interevent",
plotlyOutput("interev_dist"),
height = 7, width = 9)
)
),
fluidRow(
box(
materialSwitch(inputId = "overlay_determ",
label = "Overlay deterministic curves",
status = "success",
value = FALSE)
),
box(
textInput("filename", "Save a .csv of the dataset:",
"enter_filename_here"),
downloadButton("download", "Download")
)
)
),
tabItem(tabName = "app_descrip",
includeMarkdown("README.md")
)
)
)
# Bring it all together
dashboardPage(
dashboardHeader(title = "Stochastic simulation of epidemics",
titleWidth = 340),
sidebar,
body,
skin = "red"
)