-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
284 lines (255 loc) · 11.2 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# Load necessary library
library(shiny)
# Define the UI for the application
ui <- fluidPage(
# Add custom CSS to ensure images do not exceed the window size
tags$style(HTML("
.responsive-img {
max-width: 100%;
max-height: 500px; /* Restrict maximum height */
width: auto;
height: auto;
display: block;
margin-left: auto;
margin-right: auto;
}
.logo-banner {
max-width: 100px; /* Adjust the size as needed */
display: block;
margin-left: auto;
margin-right: auto;
}
.title-panel {
text-align: center;
font-size: 24px;
font-weight: bold;
padding-left: 20px; /* Spacing between logo and title */
display: inline-block;
}
.figure-title {
text-align: center; Ensure titles are centered */
margin-left: 15px; /* Consistent left margin for titles */
margin-top: 40px; /* Add some margin above the titles */
}
.figure-space {
margin-bottom: 60px; /* Add space between figures */
}
")),
# Include the logo and title in the same row
fluidRow(
column(1,
img(src = "logo.png", class = "logo-banner")), # Logo in the first column
column(11,
div("Dashboard de resultados do boletim InfoGripe", class = "title-panel")) # Title in the second column
),
# Create a tab layout
tabsetPanel(
# First Tab: Trends
tabPanel("Tendências",
# Two figures vertically with titles
h3("Mapa de tendência de SRAG para o curto e longo prazo - Unidades Federativas",
class = "figure-title"),
fluidRow(
imageOutput("trends_figure1", width = "100%", height = "auto")
),
h3("Mapa de tendência de SRAG para o curto e longo prazo - somente capitais",
class = "figure-title"),
fluidRow(
imageOutput("trends_figure2", width = "100%", height = "auto")
)
),
# Second Tab: Brazil
tabPanel("Brasil",
# Figures 1 and 2 side by side with a header
h3("Figura 1. Série temporal, estimativa de casos recentes de SRAG e tendências de curto (últimas 3 semanas) e longo prazo (últimas 6 semanas) em todo o território nacional - geral e por faixas etárias de interesse.",
class = "figure-title"),
fluidRow(
column(6,
imageOutput("brazil_figure1", width = "100%", height = "auto")),
column(6,
imageOutput("brazil_figure2", width = "100%", height = "auto"))
),
# Figure 3 alone with a header
h3("Figura 2. Incidência e mortalidade nas últimas 8 semanas.",
class = "figure-title"),
fluidRow(
column(12,
imageOutput("brazil_figure3", width = "100%", height = "auto"))
),
# Figures 4 and 5 side by side with a header
h3("Figura 3. Média da incidência e mortalidade semanal de SRAG nas últimas oito semanas, por vírus e faixa etária de interesse.",
class = "figure-title"),
fluidRow(
column(6,
imageOutput("brazil_figure4", width = "100%", height = "auto")),
column(6,
imageOutput("brazil_figure5", width = "100%", height = "auto"))
),
# Figure 6 alone at the bottom
h3("Figura 4. Incidência semanal de SRAG e por vírus identificado laboratorialmente, por faixas etárias de interesse.",
class = "figure-title"),
fluidRow(
column(12,
imageOutput("brazil_figure6", width = "100%", height = "auto"))
)
),
# Third Tab: Brazilian States
tabPanel("Unidades Federativas",
# Dropdown menu for selecting a state
selectInput("selected_state", "Selecione uma Unidade Federativa:",
choices = c("AC", "AL", "AP", "AM", "BA", "CE", "DF",
"ES", "GO", "MA", "MT", "MS",
"MG", "PA", "PB", "PR", "PE", "PI", "RJ",
"RN", "RS", "RO", "RR", "SC",
"SP", "SE", "TO")),
# Empty titles with space for you to add titles later
h3("Figura 1. Série temporal, estimativa de casos recentes de SRAG e tendências de curto (últimas 3 semanas) e longo prazo (últimas 6 semanas) por Unidade Federativa - geral e por faixas etárias de interesse.",
class = "figure-title"),
fluidRow(
column(6,
imageOutput("state_image1", width = "100%", height = "auto")),
column(6,
imageOutput("state_image2", width = "100%", height = "auto"))
),
h3("Figura 2. Casos semanais de SRAG e por vírus identificado laboratorialmente, por faixas etárias de interesse.",
class = "figure-title"),
fluidRow(
imageOutput("state_image3", width = "100%", height = "auto")
)
),
# Fourth Tab: Brazilian Capitals
tabPanel("Capitais",
# Alphabetically ordered dropdown menu for selecting a capital
selectInput("selected_capital", "Choose a Brazilian Capital:",
choices = sort(c("Aracaju", "Belém", "Belo Horizonte", "Boa Vista", "Brasília", "Campo Grande",
"Cuiabá", "Curitiba", "Florianópolis", "Fortaleza", "Goiânia", "João Pessoa",
"Macapá", "Maceió", "Manaus", "Natal", "Palmas", "Porto Alegre",
"Porto Velho", "Recife", "Rio Branco", "Rio de Janeiro", "Salvador",
"São Luís", "São Paulo", "Teresina", "Vitória"))),
# Display the figures with header titles
h3("Série temporal, estimativa de casos recentes de SRAG e tendências de curto (últimas 3 semanas) e longo prazo (últimas 6 semanas) por Unidade Federativa - geral e por faixas etárias de interesse.",
class = "figure-title"),
fluidRow(
column(6,
imageOutput("capital_image1", width = "100%", height = "auto")),
column(6,
imageOutput("capital_image2", width = "100%", height = "auto"))
)
)
)
)
# Define server logic
server <- function(input, output) {
### Tab 1: Trends Figures ###
output$trends_figure1 <- renderImage({
list(src = "www/Mapa_ufs_tendencia.png",
contentType = "image/png",
class = "responsive-img",
alt = "Trends Figure 1")
}, deleteFile = FALSE)
output$trends_figure2 <- renderImage({
list(src = "www/Mapa_capitais_tendencia.png",
contentType = "image/png",
class = "responsive-img",
alt = "Trends Figure 2")
}, deleteFile = FALSE)
### Tab 2: Brazil Static Figures
output$brazil_figure1 <- renderImage({
list(src = "www/fig_BR.png",
contentType = "image/png",
class = "responsive-img",
alt = "Figure 1 for Brazil")
}, deleteFile = FALSE)
output$brazil_figure2 <- renderImage({
list(src = "www/fig_BR_fx_etaria.png",
contentType = "image/png",
class = "responsive-img",
alt = "Figure 2 for Brazil")
}, deleteFile = FALSE)
output$brazil_figure3 <- renderImage({
list(src = "www/fig_BR_inc_mort.png",
contentType = "image/png",
class = "responsive-img",
alt = "Figure 3 for Brazil")
}, deleteFile = FALSE)
output$brazil_figure4 <- renderImage({
list(src = "www/fig_BR_virus_lab_inc.png",
contentType = "image/png",
class = "responsive-img",
alt = "Figure 4 for Brazil")
}, deleteFile = FALSE)
output$brazil_figure5 <- renderImage({
list(src = "www/fig_BR_virus_lab_mort.png",
contentType = "image/png",
class = "responsive-img",
alt = "Figure 5 for Brazil")
}, deleteFile = FALSE)
output$brazil_figure6 <- renderImage({
list(src = "www/fig_BR_virus_lab.png",
contentType = "image/png",
class = "responsive-img",
alt = "Figure 6 for Brazil")
}, deleteFile = FALSE)
### Tab 3: Brazilian States
get_image_path <- function(state, image_number) {
if (image_number == 1) {
return(paste0("www/fig_", state, ".png"))
} else if (image_number == 2) {
return(paste0("www/fig_", state, "_fx_etaria.png"))
} else if (image_number == 3) {
return(paste0("www/fig_", state, "_virus_lab.png"))
}
}
output$state_image1 <- renderImage({
state <- input$selected_state
list(src = get_image_path(state, 1),
contentType = "image/png",
class = "responsive-img",
alt = paste("UF", state, "Image 1"))
}, deleteFile = FALSE)
output$state_image2 <- renderImage({
state <- input$selected_state
list(src = get_image_path(state, 2),
contentType = "image/png",
class = "responsive-img",
alt = paste("UF", state, "Image 2"))
}, deleteFile = FALSE)
output$state_image3 <- renderImage({
state <- input$selected_state
list(src = get_image_path(state, 3),
contentType = "image/png",
class = "responsive-img",
alt = paste("UF", state, "Image 3"))
}, deleteFile = FALSE)
### Tab 4: Brazilian Capitals
get_capital_image_path <- function(capital) {
state_abbr <- switch(
capital,
"Rio Branco" = "AC", "Maceió" = "AL", "Macapá" = "AP", "Manaus" = "AM",
"Salvador" = "BA", "Fortaleza" = "CE", "Brasília" = "DF", "Vitória" = "ES",
"Goiânia" = "GO", "São Luís" = "MA", "Cuiabá" = "MT", "Campo Grande" = "MS",
"Belo Horizonte" = "MG", "Belém" = "PA", "João Pessoa" = "PB", "Curitiba" = "PR",
"Recife" = "PE", "Teresina" = "PI", "Rio de Janeiro" = "RJ", "Natal" = "RN",
"Porto Alegre" = "RS", "Porto Velho" = "RO", "Boa Vista" = "RR", "Florianópolis" = "SC",
"São Paulo" = "SP", "Aracaju" = "SE", "Palmas" = "TO"
)
# Return paths for capital images
paste0("www/fig_", state_abbr, "_", gsub(" ", "_", toupper(capital)))
}
output$capital_image1 <- renderImage({
capital <- input$selected_capital
list(src = paste0(get_capital_image_path(capital), ".png"),
contentType = "image/png",
class = "responsive-img",
alt = paste("Capital", capital, "Image 1"))
}, deleteFile = FALSE)
output$capital_image2 <- renderImage({
capital <- input$selected_capital
list(src = paste0(get_capital_image_path(capital), "_fx_etaria.png"),
contentType = "image/png",
class = "responsive-img",
alt = paste("Capital", capital, "Image 2"))
}, deleteFile = FALSE)
}
# Run the application
shinyApp(ui = ui, server = server)