-
Notifications
You must be signed in to change notification settings - Fork 0
/
shiny.R
196 lines (170 loc) · 7.81 KB
/
shiny.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
library(readr)
library(tidyverse)
library(shiny)
library(shinythemes)
library(rsconnect)
library(DT)
library(data.table)
library(lubridate)
theme_set(theme_bw())
# Corrija aqui o caminho que será salvo os dados
pasta <- "C:/Users/m7531296/OneDrive/Nucleo SI/Base de Dados/monitoramento-si/"
# Reading - .RData-----------------------------------------------------------------
bd_criacao_shiny <- read_csv(paste0(pasta, "bd_criacao_shiny.csv"))
bd_encerramento_shiny <- read_csv(paste0(pasta, "bd_encerramento_shiny.csv"))
bd_matricula_shiny <- read_csv(paste0(pasta, "bd_matricula_shiny.csv"))
# Wrangling ---------------------------------------------------------------
min_date <- min(bd_criacao$DATA)
max_date <- max(bd_criacao$DATA)
# Tabela agrupada
base_tabela <- bd_criacao %>%
group_by(SRE) %>%
top_n(1, wt = DATA) %>%
left_join(bd_encerramento, by = c("SRE", "DATA")) %>%
left_join(bd_matricula, by = c("SRE", "DATA")) %>%
arrange(TX_ENCERRAMENTO)
# A tabela de criação de turmas tem tratamento a parte
bd_criacao <- bd_criacao %>%
setNames(c("SRE", "DATA", "CRIACAO", "AUTORIZACAO")) %>%
gather(key = TIPO, value = TAXA, -SRE, -DATA)
# UI ----------------------------------------------------------------------
ui <- fluidPage(
theme = shinytheme("readable"),
# Titulo Aplicativo
titlePanel("Acompanhamento SI - 2018",
windowTitle = "Acompanhamento 2018"),
navbarPage(title = "",
tabPanel(title = "Tabela",
DT::DTOutput(outputId = "table_sre")),
tabPanel(title = "Evolucao",
sidebarLayout(
sidebarPanel(
# Instrucoes
tags$p("Selecione as Superintendencias que deseja vizualizar.",
" Em seguida selecione o periodo de tempo."),
# Escolher SRE
selectInput(inputId = "sre",
label = "SRE",
choices = unique(bd_criacao$SRE),
multiple = TRUE,
selected = "ALMENARA"),
# Date input
dateRangeInput(inputId = "date",
label = "Selecione o periodo",
start = "2018-01-01",
end = "2019-12-31",
min = min_date, max = max_date,
startview = "year"),
width = 3
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Criacao de Turmas", plotOutput("plot_criacao")),
tabPanel("Encerramento", plotOutput("plot_encerramento")),
tabPanel("Matricula e Enturmacao", plotOutput("plot_matricula"))),
width = 9
)
)
),
tabPanel(title = "Sobre",
tags$p("Dashboard pelo Nucleo de Gestao da Informacao da",
" Subsecretaria de Informacoes e Tecnologias",
" Educacionais da Secretaria de Estado de Educacao",
" para monitoramento de processos administrativos escolares.")
)
)
)
# SERVER ------------------------------------------------------------------
server <- function(input, output) {
output$table_sre <- DT::renderDT({
datatable(base_tabela,
selection = "none",
rownames = FALSE,
colnames = c("SRE", "Dia", "Taxa de Criacao de Turmas", "Taxa de Autorizacao",
"Taxa de Encerramento", "Taxa de Enturmacao")) %>%
formatPercentage(columns = c("TX_CRIACAO", "TX_AUTORIZACAO",
"TX_ENCERRAMENTO", "TX_ENTURMACAO"), 2)
})
# Grafico Criacao de Turmas
sre_selected_criacao <- reactive({
req(input$sre)
bd_criacao %>%
filter(SRE %in% input$sre) %>%
filter(DATA >= input$date[1] & DATA <= input$date[2])
})
output$plot_criacao <- renderPlot({
ggplot(data = sre_selected_criacao(), aes(x = DATA, y = TAXA, color = SRE, group = SRE)) +
geom_line(size = 1.5) +
scale_y_continuous(labels = scales::percent_format()) +
#scale_y_continuous(limits = c(0,1.1)) +
facet_grid(. ~ TIPO)+
labs(title = paste0("Evolucao da Enturmacao\n",
"Superintendencias Regionais de Ensino."),
x = "Dia",
y = "Percentual de Criacao e Autorizacao de Turmas",
color = "SRE",
caption = paste0("SIMADE: ", Sys.Date())) +
theme(axis.text.x = element_text(face = "bold", angle = 90, size = 17.5),
axis.text.y = element_text(face = "bold", size = 17.5),
axis.title.x = element_blank(),
axis.title.y = element_text(size = 17.5),
plot.caption = element_text(face = "bold", size = 12.5),
plot.title = element_text(face = "bold", size = 20),
legend.text = element_text(size = 12.5))
})
# Grafico Encerramento
sre_selected_encerramento <- reactive({
req(input$sre)
bd_encerramento %>%
filter(SRE %in% input$sre) %>%
filter(DATA >= input$date[1] & DATA <= input$date[2])
})
output$plot_encerramento <- renderPlot({
ggplot(data = sre_selected_encerramento(), aes(x = DATA, y = TX_ENCERRAMENTO, color = SRE, group = SRE)) +
geom_line(size = 1.5) +
scale_y_continuous(labels = scales::percent_format()) +
#scale_y_continuous(limits = c(0,1.1)) +
labs(title = paste0("Evolucao do Encerramento\n",
"Superintendencias Regionais de Ensino."),
x = "Dia",
y = "Percentual de Encerramento",
color = "SRE",
caption = paste0("SIMADE: ", Sys.Date())) +
theme(axis.text.x = element_text(face = "bold", angle = 90, size = 17.5),
axis.text.y = element_text(face = "bold", size = 17.5),
axis.title.x = element_blank(),
axis.title.y = element_text(size = 17.5),
plot.caption = element_text(face = "bold", size = 12.5),
plot.title = element_text(face = "bold", size = 20),
legend.text = element_text(size = 12.5))
})
# Grafico Matricula e Enturmacao
sre_selected_matricula <- reactive({
req(input$sre)
bd_matricula %>%
filter(SRE %in% input$sre) %>%
filter(DATA >= input$date[1] & DATA <= input$date[2])
})
output$plot_matricula <- renderPlot({
ggplot(data = sre_selected_matricula(), aes(x = DATA, y = TX_ENTURMACAO, color = SRE, group = SRE)) +
geom_line(size = 1.5) +
scale_y_continuous(labels = scales::percent_format()) +
#scale_y_continuous(limits = c(0,1.1)) +
labs(title = paste0("Evolucao da Enturmacao\n",
"Superintendencias Regionais de Ensino."),
x = "Dia",
y = "Percentual de Enturmacao",
color = "SRE",
caption = paste0("SIMADE: ", Sys.Date())) +
theme(axis.text.x = element_text(face = "bold", angle = 90, size = 17.5),
axis.text.y = element_text(face = "bold", size = 17.5),
axis.title.x = element_blank(),
axis.title.y = element_text(size = 17.5),
plot.caption = element_text(face = "bold", size = 12.5),
plot.title = element_text(face = "bold", size = 20),
legend.text = element_text(size = 12.5))
})
}
# APP ---------------------------------------------------------------------
# Run the application
shinyApp(ui = ui, server = server)