Update app.R
Browse files
app.R
CHANGED
@@ -5,18 +5,19 @@ library(dplyr)
|
|
5 |
#
|
6 |
# 0. routing
|
7 |
# --------
|
|
|
8 |
|
9 |
#
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
#
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
#
|
21 |
|
22 |
#setwd(absolute_path("assets"))
|
@@ -27,14 +28,15 @@ library(dplyr)
|
|
27 |
# --------
|
28 |
|
29 |
#
|
30 |
-
|
|
|
31 |
|
32 |
#
|
33 |
# 1.1 custom-dependencias
|
34 |
# --------
|
35 |
|
36 |
-
|
37 |
-
|
38 |
source("dataframe extention.R")
|
39 |
source("Compute_YEI.R")
|
40 |
|
@@ -44,9 +46,9 @@ source("Compute_YEI.R")
|
|
44 |
|
45 |
#
|
46 |
talk_states=list(
|
47 |
-
|
48 |
-
|
49 |
-
)
|
50 |
#
|
51 |
CURRENT_STATE="unauthenticated"
|
52 |
EXPORT_STATE=FALSE
|
@@ -56,19 +58,19 @@ credentials.authenticate=function(
|
|
56 |
input_pasword,
|
57 |
valid_credentials=data.frame(user="stockpesca", pasword="Temporal1843@!")
|
58 |
){
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
valid_credentials %>% dplyr::filter(user==input_user & pasword==input_pasword)
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
}
|
73 |
|
74 |
#
|
@@ -77,18 +79,17 @@ credentials.authenticate=function(
|
|
77 |
|
78 |
#
|
79 |
empty_table=data.frame(
|
80 |
-
|
81 |
)
|
82 |
#
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
#
|
89 |
-
|
90 |
-
|
91 |
-
#}
|
92 |
#datasource.raw_inspecciones() %>% View()
|
93 |
inspecciones.cache=NULL
|
94 |
#inspecciones.cache=datasource.raw_inspecciones()
|
@@ -98,14 +99,14 @@ inspecciones.cache=NULL
|
|
98 |
query_data=function(
|
99 |
file_path
|
100 |
){
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
# try({
|
110 |
# #
|
111 |
# setwd(absolute_path("datasource inspecciones"))
|
@@ -126,18 +127,18 @@ query_data=function(
|
|
126 |
# dbFetch(query)
|
127 |
# }) %>% as.data.frame()
|
128 |
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
-
tryCatch({
|
131 |
-
data <- readxl::read_excel(file_path)
|
132 |
-
print("Archivo leído correctamente")
|
133 |
-
data
|
134 |
-
}, error = function(e) {
|
135 |
-
print("Error al leer el archivo:")
|
136 |
-
print(e$message)
|
137 |
-
data.frame(Mensaje = "Error al leer el archivo Excel")
|
138 |
-
})
|
139 |
-
}
|
140 |
-
|
141 |
}
|
142 |
|
143 |
#
|
@@ -149,200 +150,200 @@ query_data=function(
|
|
149 |
inspecciones.activas=function(
|
150 |
inspecciones
|
151 |
){
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
}
|
161 |
#
|
162 |
inspecciones.ensamblar_variables_de_reporte=function(
|
163 |
inspecciones
|
164 |
){
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
}
|
175 |
#
|
176 |
tabla_de_reporte.formatear_ciclo_anual_en_columnas=
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
#
|
192 |
table_logic_per_index=list(
|
193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
inspecciones=inspecciones.cache
|
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 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
"1.6"=function(
|
301 |
-
inspecciones=inspecciones.cache
|
302 |
-
){
|
303 |
-
inspecciones %>%
|
304 |
-
inspecciones.activas() %>%
|
305 |
-
inspecciones.ensamblar_variables_de_reporte() %>%
|
306 |
-
|
307 |
-
split(paste(.$ano, .$mes, .$arte)) %>%
|
308 |
-
lapply(function(sub_df){
|
309 |
-
data.frame(
|
310 |
-
ano=dplyr::first(sub_df$ano),
|
311 |
-
mes=dplyr::first(sub_df$mes),
|
312 |
-
arte=dplyr::first(sub_df$arte),
|
313 |
-
reportada="(promedio) de las horas de faena x (1.3)",
|
314 |
-
horas_de_faena=round(mean(sub_df$horas_faena),3)*(1.3)
|
315 |
-
)
|
316 |
-
}) %>%
|
317 |
-
bind_rows() %>%
|
318 |
-
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
319 |
-
},
|
320 |
-
"1.7"=function(
|
321 |
-
inspecciones=inspecciones.cache
|
322 |
-
){
|
323 |
-
inspecciones %>%
|
324 |
-
inspecciones.activas() %>%
|
325 |
-
inspecciones.ensamblar_variables_de_reporte() %>%
|
326 |
-
|
327 |
-
split(paste(.$ano, .$mes, .$arte, .$AREA, .$SUBAREA )) %>%
|
328 |
-
lapply(function(sub_df){
|
329 |
-
data.frame(
|
330 |
-
ano=dplyr::first(sub_df$ano),
|
331 |
-
mes=dplyr::first(sub_df$mes),
|
332 |
-
arte=dplyr::first(sub_df$arte),
|
333 |
-
area=dplyr::first(sub_df$AREA),
|
334 |
-
subarea=dplyr::first(sub_df$SUBAREA),
|
335 |
-
reportada="(promedio) de las horas de faena x (1.3)",
|
336 |
-
horas_de_faena=round(mean(sub_df$horas_faena),3)*(1.3)
|
337 |
-
)
|
338 |
-
}) %>%
|
339 |
-
bind_rows() %>%
|
340 |
-
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
341 |
-
}
|
342 |
)
|
343 |
|
344 |
#
|
345 |
-
|
346 |
source("Compute_YEI.R")
|
347 |
#
|
348 |
table_logic_per_index[["2.1"]]=
|
@@ -397,7 +398,7 @@ table_logic_per_index[["2.3"]]=
|
|
397 |
|
398 |
"arte",
|
399 |
"sitio"
|
400 |
-
|
401 |
|
402 |
)
|
403 |
) %>%
|
@@ -438,7 +439,7 @@ table_logic_per_index[["2.5"]]=
|
|
438 |
GROUP_BY=c(
|
439 |
"ano",
|
440 |
"mes",
|
441 |
-
|
442 |
|
443 |
"arte",
|
444 |
"SUBGRUPO",
|
@@ -499,41 +500,41 @@ table_logic_per_index[["2.7"]]=
|
|
499 |
#
|
500 |
|
501 |
#
|
502 |
-
|
503 |
source("Compute_YEI.R")
|
504 |
#
|
505 |
inspecciones.ensamblar_captura_diaria=
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
510 |
|
511 |
-
|
512 |
-
|
513 |
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
)
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
)
|
529 |
-
|
530 |
-
|
531 |
-
) %>%
|
532 |
-
dplyr::mutate(
|
533 |
-
captura_diaria=round( (captura_total/num_dias),4),
|
534 |
-
captura_diaria_por_pescador=round( ( (captura_total/num_dias)/num_pescadores ),4),
|
535 |
-
)
|
536 |
-
}
|
537 |
#
|
538 |
table_logic_per_index[["3.1"]]=
|
539 |
function(
|
@@ -608,7 +609,7 @@ table_logic_per_index[["3.3"]]=
|
|
608 |
fetch_table_per_index=function(
|
609 |
index=1.1
|
610 |
){
|
611 |
-
|
612 |
}
|
613 |
#
|
614 |
table.preview=function(
|
@@ -616,10 +617,10 @@ table.preview=function(
|
|
616 |
max_rows=15,
|
617 |
max_cols=8
|
618 |
){
|
619 |
-
|
620 |
table[1:min(max_rows, nrow(table) ), 1:min(max_cols, ncol(nrow(table)))]
|
621 |
-
|
622 |
-
|
623 |
}
|
624 |
|
625 |
# 5. exportar a un reporte ?nico
|
@@ -628,178 +629,180 @@ table.preview=function(
|
|
628 |
# 6. interfaz del usuario exportar a un reporte ?nico
|
629 |
#
|
630 |
|
631 |
-
|
632 |
#
|
633 |
library(shiny)
|
634 |
ui = fluidPage(
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
accept = c(".xlsx")
|
663 |
-
))),
|
664 |
-
|
665 |
-
fluidRow(
|
666 |
-
wellPanel(
|
667 |
-
|
668 |
-
shiny::tags$strong("Reportes"),
|
669 |
-
shiny::tags$br(),
|
670 |
-
shiny::actionButton("exportar_reportes",
|
671 |
-
"Exportar reportes",
|
672 |
-
width='100%'),
|
673 |
-
textOutput("export_result")
|
674 |
-
),
|
675 |
-
plotOutput(
|
676 |
-
"logo",
|
677 |
-
width = "100%",
|
678 |
-
height = "200px")
|
679 |
-
),
|
680 |
-
|
681 |
-
), # column,
|
682 |
-
|
683 |
-
column(12-4,
|
684 |
-
|
685 |
-
offset = 1,
|
686 |
-
|
687 |
-
fluidRow(wellPanel(
|
688 |
-
shiny::tags$strong("Mensajes"),
|
689 |
-
textOutput("messages"))),
|
690 |
-
|
691 |
-
|
692 |
-
shiny::tags$strong("Pre-visualización de reportes"),
|
693 |
-
|
694 |
-
tabsetPanel(
|
695 |
-
|
696 |
-
tabPanel("0. Tabla maestra",
|
697 |
-
|
698 |
-
div(shiny::tableOutput("0_tabla_maestra"),
|
699 |
-
style = "font-size:50%")),
|
700 |
-
|
701 |
-
tabPanel("1. Esfuerzo",
|
702 |
-
|
703 |
-
tabsetPanel(
|
704 |
-
|
705 |
-
tabPanel(
|
706 |
-
"1.1",
|
707 |
-
div(shiny::tableOutput("1.1")),
|
708 |
-
style = "font-size:50%"),
|
709 |
-
|
710 |
-
tabPanel(
|
711 |
-
"1.2",
|
712 |
-
div(shiny::tableOutput("1.2")),
|
713 |
-
style = "font-size:50%"),
|
714 |
-
|
715 |
-
tabPanel(
|
716 |
-
"1.3",
|
717 |
-
div(shiny::tableOutput("1.3")),
|
718 |
-
style = "font-size:50%"
|
719 |
-
),
|
720 |
-
|
721 |
-
tabPanel(
|
722 |
-
"1.4",
|
723 |
-
div(shiny::tableOutput("1.4")),
|
724 |
-
style = "font-size:50%"),
|
725 |
-
|
726 |
-
tabPanel(
|
727 |
-
"1.5",
|
728 |
-
div(shiny::tableOutput("1.5")),
|
729 |
-
style = "font-size:50%"),
|
730 |
-
|
731 |
-
tabPanel(
|
732 |
-
"1.6",
|
733 |
-
div(shiny::tableOutput("1.6")),
|
734 |
-
style = "font-size:50%"),
|
735 |
-
|
736 |
-
tabPanel(
|
737 |
-
"1.7",
|
738 |
-
div(shiny::tableOutput("1.7")),
|
739 |
-
style = "font-size:50%")
|
740 |
-
)),
|
741 |
-
|
742 |
-
tabPanel("2. Captura total",
|
743 |
-
|
744 |
-
tabsetPanel(
|
745 |
-
|
746 |
-
tabPanel(
|
747 |
-
"2.1",
|
748 |
-
div(shiny::tableOutput("2.1")),
|
749 |
-
style = "font-size:50%"),
|
750 |
-
|
751 |
-
tabPanel(
|
752 |
-
"2.2",
|
753 |
-
div(shiny::tableOutput("2.2")),
|
754 |
-
style = "font-size:50%"),
|
755 |
-
|
756 |
-
tabPanel(
|
757 |
-
"2.3",
|
758 |
-
div(shiny::tableOutput("2.3")),
|
759 |
-
style = "font-size:50%"),
|
760 |
-
|
761 |
-
tabPanel(
|
762 |
-
"2.4",
|
763 |
-
div(shiny::tableOutput("2.4")),
|
764 |
-
style = "font-size:50%"),
|
765 |
-
|
766 |
-
tabPanel(
|
767 |
-
"2.5",
|
768 |
-
div(shiny::tableOutput("2.5")),
|
769 |
-
style = "font-size:50%"),
|
770 |
-
|
771 |
-
tabPanel(
|
772 |
-
"2.6",
|
773 |
-
div(shiny::tableOutput("2.6")),
|
774 |
-
style = "font-size:50%"),
|
775 |
-
|
776 |
-
tabPanel(
|
777 |
-
"2.7",
|
778 |
-
div(shiny::tableOutput("2.7")),
|
779 |
-
style = "font-size:50%")
|
780 |
-
)),
|
781 |
-
|
782 |
-
tabPanel("3. CPUE",
|
783 |
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
803 |
|
804 |
|
805 |
#
|
@@ -833,7 +836,7 @@ server = function(input, output) {
|
|
833 |
actualizar_mensaje_exportado=reactive({
|
834 |
exportado
|
835 |
})
|
836 |
-
|
837 |
#
|
838 |
output$"0_tabla_maestra" = renderTable({
|
839 |
|
@@ -891,309 +894,309 @@ server = function(input, output) {
|
|
891 |
width = '100%',
|
892 |
spacing = "s"
|
893 |
)
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
}
|
903 |
-
},
|
904 |
-
striped = TRUE,
|
905 |
-
hover=TRUE,
|
906 |
-
bordered=TRUE,
|
907 |
-
width='100%',
|
908 |
-
spacing="s"
|
909 |
-
)
|
910 |
-
|
911 |
-
output$"1.3" = renderTable({
|
912 |
-
if (authenticated()) {
|
913 |
-
print(paste("User is authenticated, showing results..."))
|
914 |
-
data <- fetch_table_per_index("1.3")
|
915 |
-
data
|
916 |
-
} else {
|
917 |
-
print(paste("User is not authenticated, returning error message..."))
|
918 |
-
"No tiene permisos para ver esta tabla"
|
919 |
-
}
|
920 |
-
},
|
921 |
-
striped = TRUE,
|
922 |
-
hover=TRUE,
|
923 |
-
bordered=TRUE,
|
924 |
-
width='100%',
|
925 |
-
spacing="s"
|
926 |
-
)
|
927 |
-
|
928 |
-
output$"1.4" = renderTable({
|
929 |
-
if (authenticated()) {
|
930 |
-
print(paste("User is authenticated, showing results..."))
|
931 |
-
data <- fetch_table_per_index("1.4")
|
932 |
-
data
|
933 |
-
} else {
|
934 |
-
print(paste("User is not authenticated, returning error message..."))
|
935 |
-
"No tiene permisos para ver esta tabla"
|
936 |
-
}
|
937 |
-
},
|
938 |
-
striped = TRUE,
|
939 |
-
hover=TRUE,
|
940 |
-
bordered=TRUE,
|
941 |
-
width='100%',
|
942 |
-
spacing="s"
|
943 |
-
)
|
944 |
-
output$"1.5" = renderTable({
|
945 |
-
if (authenticated()) {
|
946 |
-
print(paste("User is authenticated, showing results..."))
|
947 |
-
data <- fetch_table_per_index("1.5")
|
948 |
-
data
|
949 |
-
} else {
|
950 |
-
print(paste("User is not authenticated, returning error message..."))
|
951 |
-
"No tiene permisos para ver esta tabla"
|
952 |
-
}
|
953 |
-
},
|
954 |
-
striped = TRUE,
|
955 |
-
hover=TRUE,
|
956 |
-
bordered=TRUE,
|
957 |
-
width='100%',
|
958 |
-
spacing="s"
|
959 |
-
)
|
960 |
-
output$"1.6" = renderTable({
|
961 |
-
if (authenticated()) {
|
962 |
-
print(paste("User is authenticated, showing results..."))
|
963 |
-
data <- fetch_table_per_index("1.6")
|
964 |
-
data
|
965 |
-
} else {
|
966 |
-
print(paste("User is not authenticated, returning error message..."))
|
967 |
-
"No tiene permisos para ver esta tabla"
|
968 |
-
}
|
969 |
-
},
|
970 |
-
striped = TRUE,
|
971 |
-
hover=TRUE,
|
972 |
-
bordered=TRUE,
|
973 |
-
width='100%',
|
974 |
-
spacing="s"
|
975 |
-
)
|
976 |
-
output$"1.7" = renderTable({
|
977 |
-
if (authenticated()) {
|
978 |
-
print(paste("User is authenticated, showing results..."))
|
979 |
-
data <- fetch_table_per_index("1.7")
|
980 |
-
data
|
981 |
-
} else {
|
982 |
-
print(paste("User is not authenticated, returning error message..."))
|
983 |
-
"No tiene permisos para ver esta tabla"
|
984 |
-
}
|
985 |
-
},
|
986 |
-
striped = TRUE,
|
987 |
-
hover=TRUE,
|
988 |
-
bordered=TRUE,
|
989 |
-
width='100%',
|
990 |
-
spacing="s"
|
991 |
-
)
|
992 |
-
output$"2.1" = renderTable({
|
993 |
-
if (authenticated()) {
|
994 |
-
print(paste("User is authenticated, showing results..."))
|
995 |
-
data <- fetch_table_per_index("2.1")
|
996 |
-
data
|
997 |
-
} else {
|
998 |
-
print(paste("User is not authenticated, returning error message..."))
|
999 |
-
"No tiene permisos para ver esta tabla"
|
1000 |
-
}
|
1001 |
-
},
|
1002 |
-
striped = TRUE,
|
1003 |
-
hover=TRUE,
|
1004 |
-
bordered=TRUE,
|
1005 |
-
width='100%',
|
1006 |
-
spacing="s"
|
1007 |
-
)
|
1008 |
-
output$"2.2" = renderTable({
|
1009 |
-
if (authenticated()) {
|
1010 |
-
print(paste("User is authenticated, showing results..."))
|
1011 |
-
data <- fetch_table_per_index("2.2")
|
1012 |
-
data
|
1013 |
-
} else {
|
1014 |
-
print(paste("User is not authenticated, returning error message..."))
|
1015 |
-
"No tiene permisos para ver esta tabla"
|
1016 |
-
}
|
1017 |
-
},
|
1018 |
-
striped = TRUE,
|
1019 |
-
hover=TRUE,
|
1020 |
-
bordered=TRUE,
|
1021 |
-
width='100%',
|
1022 |
-
spacing="s"
|
1023 |
-
)
|
1024 |
-
output$"2.3" = renderTable({
|
1025 |
-
if (authenticated()) {
|
1026 |
-
print(paste("User is authenticated, showing results..."))
|
1027 |
-
data <- fetch_table_per_index("2.3")
|
1028 |
-
data
|
1029 |
-
} else {
|
1030 |
-
print(paste("User is not authenticated, returning error message..."))
|
1031 |
-
"No tiene permisos para ver esta tabla"
|
1032 |
-
}
|
1033 |
-
},
|
1034 |
-
striped = TRUE,
|
1035 |
-
hover=TRUE,
|
1036 |
-
bordered=TRUE,
|
1037 |
-
width='100%',
|
1038 |
-
spacing="s"
|
1039 |
-
)
|
1040 |
-
output$"2.4" = renderTable({
|
1041 |
-
if (authenticated()) {
|
1042 |
-
print(paste("User is authenticated, showing results..."))
|
1043 |
-
data <- fetch_table_per_index("2.4")
|
1044 |
-
data
|
1045 |
-
} else {
|
1046 |
-
print(paste("User is not authenticated, returning error message..."))
|
1047 |
-
"No tiene permisos para ver esta tabla"
|
1048 |
-
}
|
1049 |
-
},
|
1050 |
-
striped = TRUE,
|
1051 |
-
hover=TRUE,
|
1052 |
-
bordered=TRUE,
|
1053 |
-
width='100%',
|
1054 |
-
spacing="s"
|
1055 |
-
)
|
1056 |
-
output$"2.5" = renderTable({
|
1057 |
-
if (authenticated()) {
|
1058 |
-
print(paste("User is authenticated, showing results..."))
|
1059 |
-
data <- fetch_table_per_index("2.5")
|
1060 |
-
data
|
1061 |
-
} else {
|
1062 |
-
print(paste("User is not authenticated, returning error message..."))
|
1063 |
-
"No tiene permisos para ver esta tabla"
|
1064 |
-
}
|
1065 |
-
},
|
1066 |
-
striped = TRUE,
|
1067 |
-
hover=TRUE,
|
1068 |
-
bordered=TRUE,
|
1069 |
-
width='100%',
|
1070 |
-
spacing="s"
|
1071 |
-
)
|
1072 |
-
output$"2.6" = renderTable({
|
1073 |
-
if (authenticated()) {
|
1074 |
-
print(paste("User is authenticated, showing results..."))
|
1075 |
-
data <- fetch_table_per_index("2.6")
|
1076 |
-
data
|
1077 |
-
} else {
|
1078 |
-
print(paste("User is not authenticated, returning error message..."))
|
1079 |
-
"No tiene permisos para ver esta tabla"
|
1080 |
-
}
|
1081 |
-
},
|
1082 |
-
striped = TRUE,
|
1083 |
-
hover=TRUE,
|
1084 |
-
bordered=TRUE,
|
1085 |
-
width='100%',
|
1086 |
-
spacing="s"
|
1087 |
-
)
|
1088 |
-
output$"2.7" = renderTable({
|
1089 |
-
if (authenticated()) {
|
1090 |
-
print(paste("User is authenticated, showing results..."))
|
1091 |
-
data <- fetch_table_per_index("2.7")
|
1092 |
-
data
|
1093 |
-
} else {
|
1094 |
-
print(paste("User is not authenticated, returning error message..."))
|
1095 |
-
"No tiene permisos para ver esta tabla"
|
1096 |
-
}
|
1097 |
-
},
|
1098 |
-
striped = TRUE,
|
1099 |
-
hover=TRUE,
|
1100 |
-
bordered=TRUE,
|
1101 |
-
width='100%',
|
1102 |
-
spacing="s"
|
1103 |
-
)
|
1104 |
-
|
1105 |
-
output$"3.1" = renderTable({
|
1106 |
-
if (authenticated()) {
|
1107 |
-
print(paste("User is authenticated, showing results..."))
|
1108 |
-
data <- fetch_table_per_index("3.1")
|
1109 |
-
data
|
1110 |
-
} else {
|
1111 |
-
print(paste("User is not authenticated, returning error message..."))
|
1112 |
-
"No tiene permisos para ver esta tabla"
|
1113 |
-
}
|
1114 |
-
},
|
1115 |
-
striped = TRUE,
|
1116 |
-
hover=TRUE,
|
1117 |
-
bordered=TRUE,
|
1118 |
-
width='100%',
|
1119 |
-
spacing="s"
|
1120 |
-
)
|
1121 |
-
output$"3.2" = renderTable({
|
1122 |
-
if (authenticated()) {
|
1123 |
-
print(paste("User is authenticated, showing results..."))
|
1124 |
-
data <- fetch_table_per_index("3.2")
|
1125 |
-
data
|
1126 |
-
} else {
|
1127 |
-
print(paste("User is not authenticated, returning error message..."))
|
1128 |
-
"No tiene permisos para ver esta tabla"
|
1129 |
-
}
|
1130 |
-
},
|
1131 |
-
striped = TRUE,
|
1132 |
-
hover=TRUE,
|
1133 |
-
bordered=TRUE,
|
1134 |
-
width='100%',
|
1135 |
-
spacing="s"
|
1136 |
-
)
|
1137 |
-
output$"3.3" = renderTable({
|
1138 |
-
if (authenticated()) {
|
1139 |
-
print(paste("User is authenticated, showing results..."))
|
1140 |
-
data <- fetch_table_per_index("3.3")
|
1141 |
-
data
|
1142 |
-
} else {
|
1143 |
-
print(paste("User is not authenticated, returning error message..."))
|
1144 |
-
"No tiene permisos para ver esta tabla"
|
1145 |
-
}
|
1146 |
-
},
|
1147 |
-
striped = TRUE,
|
1148 |
-
hover=TRUE,
|
1149 |
-
bordered=TRUE,
|
1150 |
-
width='100%',
|
1151 |
-
spacing="s"
|
1152 |
-
)
|
1153 |
-
|
1154 |
-
output$"export_result"=renderText({
|
1155 |
-
actualizar_mensaje_exportado()
|
1156 |
-
ifelse(exportado$se_exporto==TRUE, "Felicidades! El reporte fue exportado", "Aún no has exportado el reporte")
|
1157 |
-
})
|
1158 |
-
|
1159 |
-
observeEvent(input$exportar_reportes,{
|
1160 |
-
if (.GlobalEnv[["CURRENT_STATE"]] == "authenticated") {
|
1161 |
-
# Ensure the 'reportes' directory exists
|
1162 |
-
setwd(PROYECT_HOME)
|
1163 |
-
if (!dir.exists("reportes")) {
|
1164 |
-
dir.create("reportes")
|
1165 |
}
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
1182 |
-
print(paste("Error generating report", index, ":", e$message))
|
1183 |
-
})
|
1184 |
}
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1197 |
}
|
1198 |
|
1199 |
# Run the application
|
|
|
5 |
#
|
6 |
# 0. routing
|
7 |
# --------
|
8 |
+
library(dplyr)
|
9 |
|
10 |
#
|
11 |
+
PROYECT_HOME=dirname(rstudioapi::getActiveDocumentContext()$path)
|
12 |
+
setwd(PROYECT_HOME)
|
13 |
+
list.files(getwd())
|
14 |
#
|
15 |
+
absolute_path=function(
|
16 |
+
APP_HOME
|
17 |
+
){
|
18 |
+
sprintf("%s/%s", PROYECT_HOME,APP_HOME)
|
19 |
+
}
|
20 |
+
absolute_path("datasource inspecciones")
|
21 |
#
|
22 |
|
23 |
#setwd(absolute_path("assets"))
|
|
|
28 |
# --------
|
29 |
|
30 |
#
|
31 |
+
library(shiny)
|
32 |
+
options(shiny.maxRequestSize=30*1024^2)
|
33 |
|
34 |
#
|
35 |
# 1.1 custom-dependencias
|
36 |
# --------
|
37 |
|
38 |
+
CODE_HOME=absolute_path("code")
|
39 |
+
setwd(CODE_HOME)
|
40 |
source("dataframe extention.R")
|
41 |
source("Compute_YEI.R")
|
42 |
|
|
|
46 |
|
47 |
#
|
48 |
talk_states=list(
|
49 |
+
"unauthenticated"="No has ingresado credenciales válidas aún",
|
50 |
+
"authenticated"="Estás autenticado y los reportes están listos para exportar"
|
51 |
+
)
|
52 |
#
|
53 |
CURRENT_STATE="unauthenticated"
|
54 |
EXPORT_STATE=FALSE
|
|
|
58 |
input_pasword,
|
59 |
valid_credentials=data.frame(user="stockpesca", pasword="Temporal1843@!")
|
60 |
){
|
61 |
+
#
|
62 |
+
# cambia el estado de la aplicaci?n seg?n la validez de las credenciales
|
63 |
+
#
|
64 |
+
|
65 |
+
valid=
|
66 |
valid_credentials %>% dplyr::filter(user==input_user & pasword==input_pasword)
|
67 |
+
if (nrow(valid)>0)
|
68 |
+
{ .GlobalEnv[["CURRENT_STATE"]] ="authenticated"}
|
69 |
+
else {
|
70 |
+
.GlobalEnv[["CURRENT_STATE"]] ="unauthenticated"
|
71 |
+
}
|
72 |
+
|
73 |
+
print(.GlobalEnv[["CURRENT_STATE"]])
|
74 |
}
|
75 |
|
76 |
#
|
|
|
79 |
|
80 |
#
|
81 |
empty_table=data.frame(
|
82 |
+
data=c("No tiene permisos para ver esta tabla")
|
83 |
)
|
84 |
#
|
85 |
+
datasource.raw_inspecciones=function(
|
86 |
+
|
87 |
+
){
|
88 |
+
setwd(absolute_path("datasource inspecciones"))
|
89 |
+
readxl::read_excel("TABLA MAESTRA.xlsx") %>%
|
90 |
+
#head() %>%
|
91 |
+
as.data.frame()
|
92 |
+
}
|
|
|
93 |
#datasource.raw_inspecciones() %>% View()
|
94 |
inspecciones.cache=NULL
|
95 |
#inspecciones.cache=datasource.raw_inspecciones()
|
|
|
99 |
query_data=function(
|
100 |
file_path
|
101 |
){
|
102 |
+
if(.GlobalEnv[["CURRENT_STATE"]]=="unauthenticated"){
|
103 |
+
empty_table
|
104 |
+
} else {
|
105 |
+
# datasource.raw_inspecciones()
|
106 |
+
# #
|
107 |
+
# user_input_pwd="Temporal1843@!"
|
108 |
+
# db_file_name="inspecciones.accdb"
|
109 |
+
#
|
110 |
# try({
|
111 |
# #
|
112 |
# setwd(absolute_path("datasource inspecciones"))
|
|
|
127 |
# dbFetch(query)
|
128 |
# }) %>% as.data.frame()
|
129 |
#
|
130 |
+
|
131 |
+
tryCatch({
|
132 |
+
data <- readxl::read_excel(file_path)
|
133 |
+
print("Archivo leído correctamente")
|
134 |
+
data
|
135 |
+
}, error = function(e) {
|
136 |
+
print("Error al leer el archivo:")
|
137 |
+
print(e$message)
|
138 |
+
data.frame(Mensaje = "Error al leer el archivo Excel")
|
139 |
+
})
|
140 |
+
}
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
}
|
143 |
|
144 |
#
|
|
|
150 |
inspecciones.activas=function(
|
151 |
inspecciones
|
152 |
){
|
153 |
+
inspecciones %>%
|
154 |
+
#
|
155 |
+
dplyr::mutate(
|
156 |
+
activa=TRUE
|
157 |
+
) %>%
|
158 |
+
dplyr::filter(
|
159 |
+
activa
|
160 |
+
)
|
161 |
}
|
162 |
#
|
163 |
inspecciones.ensamblar_variables_de_reporte=function(
|
164 |
inspecciones
|
165 |
){
|
166 |
+
inspecciones %>%
|
167 |
+
dplyr::mutate(
|
168 |
+
ano=ANO_ZARPE,
|
169 |
+
mes=MES_ZARPE,
|
170 |
+
arte=ARTE,
|
171 |
+
sitio=SITIO,
|
172 |
+
fecha=paste(ANO_ZARPE, MES_ZARPE, DIA_ZARPE, sep="+" ),
|
173 |
+
horas_faena=HORA_FAENA
|
174 |
+
)
|
175 |
}
|
176 |
#
|
177 |
tabla_de_reporte.formatear_ciclo_anual_en_columnas=
|
178 |
+
function(
|
179 |
+
Tabla_de_reporte
|
180 |
+
){
|
181 |
+
Tabla_de_reporte %>%
|
182 |
+
tidyr::pivot_wider(
|
183 |
+
names_from = mes,
|
184 |
+
names_prefix = "month_",
|
185 |
+
values_from = dplyr::last(names(.))
|
186 |
+
) %>%
|
187 |
+
Dataframe.order(
|
188 |
+
c( grep(names(.), pattern="^[^m]", value=TRUE),
|
189 |
+
paste("month_", 1:12, sep=""))
|
190 |
+
)
|
191 |
+
}
|
192 |
#
|
193 |
table_logic_per_index=list(
|
194 |
+
"1.1"=function(
|
195 |
+
inspecciones=inspecciones.cache
|
196 |
+
){
|
197 |
+
inspecciones %>%
|
198 |
+
inspecciones.activas() %>%
|
199 |
+
inspecciones.ensamblar_variables_de_reporte() %>%
|
200 |
+
|
201 |
+
split(paste(.$ano, .$mes, .$arte)) %>%
|
202 |
+
lapply(function(sub_df){
|
203 |
+
data.frame(
|
204 |
+
ano=dplyr::first(sub_df$ano),
|
205 |
+
mes=dplyr::first(sub_df$mes),
|
206 |
+
arte=dplyr::first(sub_df$arte),
|
207 |
+
reportada="(conteo) faenas activas",
|
208 |
+
faenas_activas=sub_df %>% nrow()
|
209 |
+
)
|
210 |
+
}) %>%
|
211 |
+
bind_rows() %>%
|
212 |
+
|
213 |
+
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
214 |
+
},
|
215 |
+
"1.2"=function(
|
216 |
+
inspecciones=inspecciones.cache
|
217 |
+
){
|
218 |
+
inspecciones %>%
|
219 |
+
inspecciones.activas() %>%
|
220 |
+
inspecciones.ensamblar_variables_de_reporte() %>%
|
221 |
+
|
222 |
+
split(paste(.$ano, .$mes, .$arte, .$sitio)) %>%
|
223 |
+
lapply(function(sub_df){
|
224 |
+
data.frame(
|
225 |
+
ano=dplyr::first(sub_df$ano),
|
226 |
+
mes=dplyr::first(sub_df$mes),
|
227 |
+
arte=dplyr::first(sub_df$arte),
|
228 |
+
sitio=dplyr::first(sub_df$sitio),
|
229 |
+
reportada="(conteo) faenas activas",
|
230 |
+
faenas_activas=sub_df %>% nrow()
|
231 |
+
)
|
232 |
+
}) %>%
|
233 |
+
bind_rows() %>%
|
234 |
+
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
235 |
+
},
|
236 |
+
"1.3"=function(
|
237 |
inspecciones=inspecciones.cache
|
238 |
+
){
|
239 |
+
inspecciones %>%
|
240 |
+
inspecciones.activas() %>%
|
241 |
+
inspecciones.ensamblar_variables_de_reporte() %>%
|
242 |
+
|
243 |
+
split(paste(.$ano, .$mes, .$arte, .$AREA, .$SUBAREA)) %>%
|
244 |
+
lapply(function(sub_df){
|
245 |
+
data.frame(
|
246 |
+
ano=dplyr::first(sub_df$ano),
|
247 |
+
mes=dplyr::first(sub_df$mes),
|
248 |
+
arte=dplyr::first(sub_df$arte),
|
249 |
+
area=dplyr::first(sub_df$AREA),
|
250 |
+
subarea=dplyr::first(sub_df$SUBAREA),
|
251 |
+
reportada="(conteo) faenas activas",
|
252 |
+
faenas_activas=nrow(sub_df)
|
253 |
+
)
|
254 |
+
}) %>%
|
255 |
+
bind_rows() %>%
|
256 |
+
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
257 |
+
},
|
258 |
+
"1.4"=function(
|
259 |
+
inspecciones=inspecciones.cache
|
260 |
+
){
|
261 |
+
inspecciones %>%
|
262 |
+
inspecciones.activas() %>%
|
263 |
+
inspecciones.ensamblar_variables_de_reporte() %>%
|
264 |
+
|
265 |
+
split(paste(.$ano, .$mes, .$arte)) %>%
|
266 |
+
lapply(function(sub_df){
|
267 |
+
data.frame(
|
268 |
+
ano=dplyr::first(sub_df$ano),
|
269 |
+
mes=dplyr::first(sub_df$mes),
|
270 |
+
arte=dplyr::first(sub_df$arte),
|
271 |
+
reportada="dias de actividad",
|
272 |
+
dias_actividad=length(unique(sub_df$fecha))
|
273 |
+
)
|
274 |
+
}) %>%
|
275 |
+
bind_rows() %>%
|
276 |
+
|
277 |
+
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
278 |
+
|
279 |
+
},
|
280 |
+
"1.5"=function(
|
281 |
+
inspecciones=inspecciones.cache
|
282 |
+
){
|
283 |
+
inspecciones %>%
|
284 |
+
inspecciones.activas() %>%
|
285 |
+
inspecciones.ensamblar_variables_de_reporte() %>%
|
286 |
+
|
287 |
+
split(paste(.$ano, .$mes, .$arte, .$sitio)) %>%
|
288 |
+
lapply(function(sub_df){
|
289 |
+
data.frame(
|
290 |
+
ano=dplyr::first(sub_df$ano),
|
291 |
+
mes=dplyr::first(sub_df$mes),
|
292 |
+
arte=dplyr::first(sub_df$arte),
|
293 |
+
sitio=dplyr::first(sub_df$sitio),
|
294 |
+
reportada="dias de actividad",
|
295 |
+
dias_actividad=length(unique(sub_df$fecha))
|
296 |
+
)
|
297 |
+
}) %>%
|
298 |
+
bind_rows() %>%
|
299 |
+
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
300 |
+
},
|
301 |
+
"1.6"=function(
|
302 |
+
inspecciones=inspecciones.cache
|
303 |
+
){
|
304 |
+
inspecciones %>%
|
305 |
+
inspecciones.activas() %>%
|
306 |
+
inspecciones.ensamblar_variables_de_reporte() %>%
|
307 |
+
|
308 |
+
split(paste(.$ano, .$mes, .$arte)) %>%
|
309 |
+
lapply(function(sub_df){
|
310 |
+
data.frame(
|
311 |
+
ano=dplyr::first(sub_df$ano),
|
312 |
+
mes=dplyr::first(sub_df$mes),
|
313 |
+
arte=dplyr::first(sub_df$arte),
|
314 |
+
reportada="(promedio) de las horas de faena x (1.3)",
|
315 |
+
horas_de_faena=round(mean(sub_df$horas_faena),3)*(1.3)
|
316 |
+
)
|
317 |
+
}) %>%
|
318 |
+
bind_rows() %>%
|
319 |
+
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
320 |
+
},
|
321 |
+
"1.7"=function(
|
322 |
+
inspecciones=inspecciones.cache
|
323 |
+
){
|
324 |
+
inspecciones %>%
|
325 |
+
inspecciones.activas() %>%
|
326 |
+
inspecciones.ensamblar_variables_de_reporte() %>%
|
327 |
+
|
328 |
+
split(paste(.$ano, .$mes, .$arte, .$AREA, .$SUBAREA )) %>%
|
329 |
+
lapply(function(sub_df){
|
330 |
+
data.frame(
|
331 |
+
ano=dplyr::first(sub_df$ano),
|
332 |
+
mes=dplyr::first(sub_df$mes),
|
333 |
+
arte=dplyr::first(sub_df$arte),
|
334 |
+
area=dplyr::first(sub_df$AREA),
|
335 |
+
subarea=dplyr::first(sub_df$SUBAREA),
|
336 |
+
reportada="(promedio) de las horas de faena x (1.3)",
|
337 |
+
horas_de_faena=round(mean(sub_df$horas_faena),3)*(1.3)
|
338 |
+
)
|
339 |
+
}) %>%
|
340 |
+
bind_rows() %>%
|
341 |
+
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
342 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
343 |
)
|
344 |
|
345 |
#
|
346 |
+
setwd(CODE_HOME)
|
347 |
source("Compute_YEI.R")
|
348 |
#
|
349 |
table_logic_per_index[["2.1"]]=
|
|
|
398 |
|
399 |
"arte",
|
400 |
"sitio"
|
401 |
+
|
402 |
|
403 |
)
|
404 |
) %>%
|
|
|
439 |
GROUP_BY=c(
|
440 |
"ano",
|
441 |
"mes",
|
442 |
+
|
443 |
|
444 |
"arte",
|
445 |
"SUBGRUPO",
|
|
|
500 |
#
|
501 |
|
502 |
#
|
503 |
+
setwd(CODE_HOME)
|
504 |
source("Compute_YEI.R")
|
505 |
#
|
506 |
inspecciones.ensamblar_captura_diaria=
|
507 |
+
function(
|
508 |
+
inspecciones=inspecciones.cache
|
509 |
+
){
|
510 |
+
inspecciones %>%
|
511 |
+
|
512 |
+
inspecciones.activas() %>%
|
513 |
+
inspecciones.ensamblar_variables_de_reporte() %>%
|
514 |
+
|
515 |
+
dplyr::transmute(
|
516 |
+
captura_total=CT_KG,
|
517 |
|
518 |
+
dia_zarpe=paste(ANO_ZARPE, MES_ZARPE , DIA_ZARPE, sep="/" ),
|
519 |
+
dia_arribo=paste(ANO_ARRIBO, MES_ARRIBO, DIA_ARRIBO, sep="/" ),
|
520 |
|
521 |
+
num_pescadores=PESCADORES,
|
522 |
+
|
523 |
+
arte_pesca=ARTE,
|
524 |
+
grupo=GRUPO
|
525 |
+
) %>%
|
526 |
+
dplyr::mutate(
|
527 |
+
dia_zarpe=as.Date(dia_zarpe),
|
528 |
+
dia_arribo=as.Date(dia_arribo)
|
529 |
+
) %>%
|
530 |
+
dplyr::mutate(
|
531 |
+
num_dias=as.numeric((dia_arribo-dia_zarpe)+1)
|
532 |
+
) %>%
|
533 |
+
dplyr::mutate(
|
534 |
+
captura_diaria=round( (captura_total/num_dias),4),
|
535 |
+
captura_diaria_por_pescador=round( ( (captura_total/num_dias)/num_pescadores ),4),
|
536 |
+
)
|
537 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
#
|
539 |
table_logic_per_index[["3.1"]]=
|
540 |
function(
|
|
|
609 |
fetch_table_per_index=function(
|
610 |
index=1.1
|
611 |
){
|
612 |
+
table_logic_per_index[[index]]()
|
613 |
}
|
614 |
#
|
615 |
table.preview=function(
|
|
|
617 |
max_rows=15,
|
618 |
max_cols=8
|
619 |
){
|
620 |
+
tryCatch({
|
621 |
table[1:min(max_rows, nrow(table) ), 1:min(max_cols, ncol(nrow(table)))]
|
622 |
+
},
|
623 |
+
error = function(e){empty_table})
|
624 |
}
|
625 |
|
626 |
# 5. exportar a un reporte ?nico
|
|
|
629 |
# 6. interfaz del usuario exportar a un reporte ?nico
|
630 |
#
|
631 |
|
632 |
+
setwd(PROYECT_HOME)
|
633 |
#
|
634 |
library(shiny)
|
635 |
ui = fluidPage(
|
636 |
+
|
637 |
+
|
638 |
+
column(3,
|
639 |
+
fluidRow(
|
640 |
+
wellPanel(
|
641 |
+
shiny::HTML("<p> Bienvenido a la <strong> aplicación pesquera </strong>. Escoja una acción </p>")
|
642 |
+
)),
|
643 |
+
|
644 |
+
fluidRow(
|
645 |
+
wellPanel(
|
646 |
+
shiny::tags$strong("Credenciales"),
|
647 |
+
|
648 |
+
shiny::textInput("usuario",
|
649 |
+
label=NULL,
|
650 |
+
placeholder = "inserte usuario",
|
651 |
+
width='100%'),
|
652 |
+
shiny::passwordInput("contrasena",
|
653 |
+
label=NULL,
|
654 |
+
placeholder = "inserte contrasena",
|
655 |
+
width='100%')
|
656 |
+
# shiny::actionButton("enviar_credenciales",
|
657 |
+
# "Enviar credenciales",
|
658 |
+
# width='100%')
|
659 |
+
)),
|
660 |
+
|
661 |
+
fluidRow(
|
662 |
+
wellPanel(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
663 |
|
664 |
+
fileInput('main_file_input', 'Seleccione un archivo desde su computador',
|
665 |
+
accept = c(".xlsx")
|
666 |
+
))),
|
667 |
+
|
668 |
+
fluidRow(
|
669 |
+
wellPanel(
|
670 |
+
|
671 |
+
shiny::tags$strong("Reportes"),
|
672 |
+
shiny::tags$br(),
|
673 |
+
shiny::actionButton("exportar_reportes",
|
674 |
+
"Exportar reportes",
|
675 |
+
width='100%'),
|
676 |
+
textOutput("export_result")
|
677 |
+
),
|
678 |
+
plotOutput(
|
679 |
+
"logo",
|
680 |
+
width = "100%",
|
681 |
+
height = "200px")
|
682 |
+
),
|
683 |
+
|
684 |
+
), # column,
|
685 |
+
|
686 |
+
column(12-4,
|
687 |
+
|
688 |
+
offset = 1,
|
689 |
+
|
690 |
+
fluidRow(wellPanel(
|
691 |
+
shiny::tags$strong("Mensajes"),
|
692 |
+
textOutput("messages"))),
|
693 |
+
|
694 |
+
|
695 |
+
shiny::tags$strong("Pre-visualización de reportes"),
|
696 |
+
|
697 |
+
tabsetPanel(
|
698 |
+
|
699 |
+
tabPanel("0. Tabla maestra",
|
700 |
+
|
701 |
+
div(shiny::tableOutput("0_tabla_maestra"),
|
702 |
+
style = "font-size:50%")),
|
703 |
+
|
704 |
+
tabPanel("1. Esfuerzo",
|
705 |
+
|
706 |
+
tabsetPanel(
|
707 |
+
|
708 |
+
tabPanel(
|
709 |
+
"1.1",
|
710 |
+
div(shiny::tableOutput("1.1")),
|
711 |
+
style = "font-size:50%"),
|
712 |
+
|
713 |
+
tabPanel(
|
714 |
+
"1.2",
|
715 |
+
div(shiny::tableOutput("1.2")),
|
716 |
+
style = "font-size:50%"),
|
717 |
+
|
718 |
+
tabPanel(
|
719 |
+
"1.3",
|
720 |
+
div(shiny::tableOutput("1.3")),
|
721 |
+
style = "font-size:50%"
|
722 |
+
),
|
723 |
+
|
724 |
+
tabPanel(
|
725 |
+
"1.4",
|
726 |
+
div(shiny::tableOutput("1.4")),
|
727 |
+
style = "font-size:50%"),
|
728 |
+
|
729 |
+
tabPanel(
|
730 |
+
"1.5",
|
731 |
+
div(shiny::tableOutput("1.5")),
|
732 |
+
style = "font-size:50%"),
|
733 |
+
|
734 |
+
tabPanel(
|
735 |
+
"1.6",
|
736 |
+
div(shiny::tableOutput("1.6")),
|
737 |
+
style = "font-size:50%"),
|
738 |
+
|
739 |
+
tabPanel(
|
740 |
+
"1.7",
|
741 |
+
div(shiny::tableOutput("1.7")),
|
742 |
+
style = "font-size:50%")
|
743 |
+
)),
|
744 |
+
|
745 |
+
tabPanel("2. Captura total",
|
746 |
+
|
747 |
+
tabsetPanel(
|
748 |
+
|
749 |
+
tabPanel(
|
750 |
+
"2.1",
|
751 |
+
div(shiny::tableOutput("2.1")),
|
752 |
+
style = "font-size:50%"),
|
753 |
+
|
754 |
+
tabPanel(
|
755 |
+
"2.2",
|
756 |
+
div(shiny::tableOutput("2.2")),
|
757 |
+
style = "font-size:50%"),
|
758 |
+
|
759 |
+
tabPanel(
|
760 |
+
"2.3",
|
761 |
+
div(shiny::tableOutput("2.3")),
|
762 |
+
style = "font-size:50%"),
|
763 |
+
|
764 |
+
tabPanel(
|
765 |
+
"2.4",
|
766 |
+
div(shiny::tableOutput("2.4")),
|
767 |
+
style = "font-size:50%"),
|
768 |
+
|
769 |
+
tabPanel(
|
770 |
+
"2.5",
|
771 |
+
div(shiny::tableOutput("2.5")),
|
772 |
+
style = "font-size:50%"),
|
773 |
+
|
774 |
+
tabPanel(
|
775 |
+
"2.6",
|
776 |
+
div(shiny::tableOutput("2.6")),
|
777 |
+
style = "font-size:50%"),
|
778 |
+
|
779 |
+
tabPanel(
|
780 |
+
"2.7",
|
781 |
+
div(shiny::tableOutput("2.7")),
|
782 |
+
style = "font-size:50%")
|
783 |
+
)),
|
784 |
+
|
785 |
+
tabPanel("3. CPUE",
|
786 |
+
|
787 |
+
tabsetPanel(
|
788 |
+
|
789 |
+
tabPanel(
|
790 |
+
"3.1",
|
791 |
+
div(shiny::tableOutput("3.1")),
|
792 |
+
style = "font-size:50%"),
|
793 |
+
|
794 |
+
tabPanel(
|
795 |
+
"3.2",
|
796 |
+
div(shiny::tableOutput("3.2")),
|
797 |
+
style = "font-size:50%"),
|
798 |
+
|
799 |
+
tabPanel(
|
800 |
+
"3.3",
|
801 |
+
div(shiny::tableOutput("3.3")),
|
802 |
+
style = "font-size:50%")))
|
803 |
+
|
804 |
+
# )),
|
805 |
+
)))
|
806 |
|
807 |
|
808 |
#
|
|
|
836 |
actualizar_mensaje_exportado=reactive({
|
837 |
exportado
|
838 |
})
|
839 |
+
|
840 |
#
|
841 |
output$"0_tabla_maestra" = renderTable({
|
842 |
|
|
|
894 |
width = '100%',
|
895 |
spacing = "s"
|
896 |
)
|
897 |
+
output$"1.2" = renderTable({
|
898 |
+
if (authenticated()) {
|
899 |
+
print(paste("User is authenticated, showing results..."))
|
900 |
+
data <- fetch_table_per_index("1.2")
|
901 |
+
data
|
902 |
+
} else {
|
903 |
+
print(paste("User is not authenticated, returning error message..."))
|
904 |
+
"No tiene permisos para ver esta tabla"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
905 |
}
|
906 |
+
},
|
907 |
+
striped = TRUE,
|
908 |
+
hover=TRUE,
|
909 |
+
bordered=TRUE,
|
910 |
+
width='100%',
|
911 |
+
spacing="s"
|
912 |
+
)
|
913 |
+
|
914 |
+
output$"1.3" = renderTable({
|
915 |
+
if (authenticated()) {
|
916 |
+
print(paste("User is authenticated, showing results..."))
|
917 |
+
data <- fetch_table_per_index("1.3")
|
918 |
+
data
|
919 |
+
} else {
|
920 |
+
print(paste("User is not authenticated, returning error message..."))
|
921 |
+
"No tiene permisos para ver esta tabla"
|
|
|
|
|
922 |
}
|
923 |
+
},
|
924 |
+
striped = TRUE,
|
925 |
+
hover=TRUE,
|
926 |
+
bordered=TRUE,
|
927 |
+
width='100%',
|
928 |
+
spacing="s"
|
929 |
+
)
|
930 |
+
|
931 |
+
output$"1.4" = renderTable({
|
932 |
+
if (authenticated()) {
|
933 |
+
print(paste("User is authenticated, showing results..."))
|
934 |
+
data <- fetch_table_per_index("1.4")
|
935 |
+
data
|
936 |
+
} else {
|
937 |
+
print(paste("User is not authenticated, returning error message..."))
|
938 |
+
"No tiene permisos para ver esta tabla"
|
939 |
+
}
|
940 |
+
},
|
941 |
+
striped = TRUE,
|
942 |
+
hover=TRUE,
|
943 |
+
bordered=TRUE,
|
944 |
+
width='100%',
|
945 |
+
spacing="s"
|
946 |
+
)
|
947 |
+
output$"1.5" = renderTable({
|
948 |
+
if (authenticated()) {
|
949 |
+
print(paste("User is authenticated, showing results..."))
|
950 |
+
data <- fetch_table_per_index("1.5")
|
951 |
+
data
|
952 |
+
} else {
|
953 |
+
print(paste("User is not authenticated, returning error message..."))
|
954 |
+
"No tiene permisos para ver esta tabla"
|
955 |
+
}
|
956 |
+
},
|
957 |
+
striped = TRUE,
|
958 |
+
hover=TRUE,
|
959 |
+
bordered=TRUE,
|
960 |
+
width='100%',
|
961 |
+
spacing="s"
|
962 |
+
)
|
963 |
+
output$"1.6" = renderTable({
|
964 |
+
if (authenticated()) {
|
965 |
+
print(paste("User is authenticated, showing results..."))
|
966 |
+
data <- fetch_table_per_index("1.6")
|
967 |
+
data
|
968 |
+
} else {
|
969 |
+
print(paste("User is not authenticated, returning error message..."))
|
970 |
+
"No tiene permisos para ver esta tabla"
|
971 |
+
}
|
972 |
+
},
|
973 |
+
striped = TRUE,
|
974 |
+
hover=TRUE,
|
975 |
+
bordered=TRUE,
|
976 |
+
width='100%',
|
977 |
+
spacing="s"
|
978 |
+
)
|
979 |
+
output$"1.7" = renderTable({
|
980 |
+
if (authenticated()) {
|
981 |
+
print(paste("User is authenticated, showing results..."))
|
982 |
+
data <- fetch_table_per_index("1.7")
|
983 |
+
data
|
984 |
+
} else {
|
985 |
+
print(paste("User is not authenticated, returning error message..."))
|
986 |
+
"No tiene permisos para ver esta tabla"
|
987 |
+
}
|
988 |
+
},
|
989 |
+
striped = TRUE,
|
990 |
+
hover=TRUE,
|
991 |
+
bordered=TRUE,
|
992 |
+
width='100%',
|
993 |
+
spacing="s"
|
994 |
+
)
|
995 |
+
output$"2.1" = renderTable({
|
996 |
+
if (authenticated()) {
|
997 |
+
print(paste("User is authenticated, showing results..."))
|
998 |
+
data <- fetch_table_per_index("2.1")
|
999 |
+
data
|
1000 |
+
} else {
|
1001 |
+
print(paste("User is not authenticated, returning error message..."))
|
1002 |
+
"No tiene permisos para ver esta tabla"
|
1003 |
+
}
|
1004 |
+
},
|
1005 |
+
striped = TRUE,
|
1006 |
+
hover=TRUE,
|
1007 |
+
bordered=TRUE,
|
1008 |
+
width='100%',
|
1009 |
+
spacing="s"
|
1010 |
+
)
|
1011 |
+
output$"2.2" = renderTable({
|
1012 |
+
if (authenticated()) {
|
1013 |
+
print(paste("User is authenticated, showing results..."))
|
1014 |
+
data <- fetch_table_per_index("2.2")
|
1015 |
+
data
|
1016 |
+
} else {
|
1017 |
+
print(paste("User is not authenticated, returning error message..."))
|
1018 |
+
"No tiene permisos para ver esta tabla"
|
1019 |
+
}
|
1020 |
+
},
|
1021 |
+
striped = TRUE,
|
1022 |
+
hover=TRUE,
|
1023 |
+
bordered=TRUE,
|
1024 |
+
width='100%',
|
1025 |
+
spacing="s"
|
1026 |
+
)
|
1027 |
+
output$"2.3" = renderTable({
|
1028 |
+
if (authenticated()) {
|
1029 |
+
print(paste("User is authenticated, showing results..."))
|
1030 |
+
data <- fetch_table_per_index("2.3")
|
1031 |
+
data
|
1032 |
+
} else {
|
1033 |
+
print(paste("User is not authenticated, returning error message..."))
|
1034 |
+
"No tiene permisos para ver esta tabla"
|
1035 |
+
}
|
1036 |
+
},
|
1037 |
+
striped = TRUE,
|
1038 |
+
hover=TRUE,
|
1039 |
+
bordered=TRUE,
|
1040 |
+
width='100%',
|
1041 |
+
spacing="s"
|
1042 |
+
)
|
1043 |
+
output$"2.4" = renderTable({
|
1044 |
+
if (authenticated()) {
|
1045 |
+
print(paste("User is authenticated, showing results..."))
|
1046 |
+
data <- fetch_table_per_index("2.4")
|
1047 |
+
data
|
1048 |
+
} else {
|
1049 |
+
print(paste("User is not authenticated, returning error message..."))
|
1050 |
+
"No tiene permisos para ver esta tabla"
|
1051 |
+
}
|
1052 |
+
},
|
1053 |
+
striped = TRUE,
|
1054 |
+
hover=TRUE,
|
1055 |
+
bordered=TRUE,
|
1056 |
+
width='100%',
|
1057 |
+
spacing="s"
|
1058 |
+
)
|
1059 |
+
output$"2.5" = renderTable({
|
1060 |
+
if (authenticated()) {
|
1061 |
+
print(paste("User is authenticated, showing results..."))
|
1062 |
+
data <- fetch_table_per_index("2.5")
|
1063 |
+
data
|
1064 |
+
} else {
|
1065 |
+
print(paste("User is not authenticated, returning error message..."))
|
1066 |
+
"No tiene permisos para ver esta tabla"
|
1067 |
+
}
|
1068 |
+
},
|
1069 |
+
striped = TRUE,
|
1070 |
+
hover=TRUE,
|
1071 |
+
bordered=TRUE,
|
1072 |
+
width='100%',
|
1073 |
+
spacing="s"
|
1074 |
+
)
|
1075 |
+
output$"2.6" = renderTable({
|
1076 |
+
if (authenticated()) {
|
1077 |
+
print(paste("User is authenticated, showing results..."))
|
1078 |
+
data <- fetch_table_per_index("2.6")
|
1079 |
+
data
|
1080 |
+
} else {
|
1081 |
+
print(paste("User is not authenticated, returning error message..."))
|
1082 |
+
"No tiene permisos para ver esta tabla"
|
1083 |
+
}
|
1084 |
+
},
|
1085 |
+
striped = TRUE,
|
1086 |
+
hover=TRUE,
|
1087 |
+
bordered=TRUE,
|
1088 |
+
width='100%',
|
1089 |
+
spacing="s"
|
1090 |
+
)
|
1091 |
+
output$"2.7" = renderTable({
|
1092 |
+
if (authenticated()) {
|
1093 |
+
print(paste("User is authenticated, showing results..."))
|
1094 |
+
data <- fetch_table_per_index("2.7")
|
1095 |
+
data
|
1096 |
+
} else {
|
1097 |
+
print(paste("User is not authenticated, returning error message..."))
|
1098 |
+
"No tiene permisos para ver esta tabla"
|
1099 |
+
}
|
1100 |
+
},
|
1101 |
+
striped = TRUE,
|
1102 |
+
hover=TRUE,
|
1103 |
+
bordered=TRUE,
|
1104 |
+
width='100%',
|
1105 |
+
spacing="s"
|
1106 |
+
)
|
1107 |
+
|
1108 |
+
output$"3.1" = renderTable({
|
1109 |
+
if (authenticated()) {
|
1110 |
+
print(paste("User is authenticated, showing results..."))
|
1111 |
+
data <- fetch_table_per_index("3.1")
|
1112 |
+
data
|
1113 |
+
} else {
|
1114 |
+
print(paste("User is not authenticated, returning error message..."))
|
1115 |
+
"No tiene permisos para ver esta tabla"
|
1116 |
+
}
|
1117 |
+
},
|
1118 |
+
striped = TRUE,
|
1119 |
+
hover=TRUE,
|
1120 |
+
bordered=TRUE,
|
1121 |
+
width='100%',
|
1122 |
+
spacing="s"
|
1123 |
+
)
|
1124 |
+
output$"3.2" = renderTable({
|
1125 |
+
if (authenticated()) {
|
1126 |
+
print(paste("User is authenticated, showing results..."))
|
1127 |
+
data <- fetch_table_per_index("3.2")
|
1128 |
+
data
|
1129 |
+
} else {
|
1130 |
+
print(paste("User is not authenticated, returning error message..."))
|
1131 |
+
"No tiene permisos para ver esta tabla"
|
1132 |
+
}
|
1133 |
+
},
|
1134 |
+
striped = TRUE,
|
1135 |
+
hover=TRUE,
|
1136 |
+
bordered=TRUE,
|
1137 |
+
width='100%',
|
1138 |
+
spacing="s"
|
1139 |
+
)
|
1140 |
+
output$"3.3" = renderTable({
|
1141 |
+
if (authenticated()) {
|
1142 |
+
print(paste("User is authenticated, showing results..."))
|
1143 |
+
data <- fetch_table_per_index("3.3")
|
1144 |
+
data
|
1145 |
+
} else {
|
1146 |
+
print(paste("User is not authenticated, returning error message..."))
|
1147 |
+
"No tiene permisos para ver esta tabla"
|
1148 |
+
}
|
1149 |
+
},
|
1150 |
+
striped = TRUE,
|
1151 |
+
hover=TRUE,
|
1152 |
+
bordered=TRUE,
|
1153 |
+
width='100%',
|
1154 |
+
spacing="s"
|
1155 |
+
)
|
1156 |
+
|
1157 |
+
output$"export_result"=renderText({
|
1158 |
+
actualizar_mensaje_exportado()
|
1159 |
+
ifelse(exportado$se_exporto==TRUE, "Felicidades! El reporte fue exportado", "Aún no has exportado el reporte")
|
1160 |
+
})
|
1161 |
+
|
1162 |
+
observeEvent(input$exportar_reportes,{
|
1163 |
+
if (.GlobalEnv[["CURRENT_STATE"]] == "authenticated") {
|
1164 |
+
# Ensure the 'reportes' directory exists
|
1165 |
+
setwd(PROYECT_HOME)
|
1166 |
+
if (!dir.exists("reportes")) {
|
1167 |
+
dir.create("reportes")
|
1168 |
+
}
|
1169 |
+
setwd("reportes")
|
1170 |
+
|
1171 |
+
# Create a new workbook
|
1172 |
+
wb <- openxlsx::createWorkbook()
|
1173 |
+
|
1174 |
+
# Generate and add each report to a separate sheet
|
1175 |
+
report_indices <- c("1.1", "1.2","1.3", "1.4", "1.5", "1.6", "1.7",
|
1176 |
+
"2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7",
|
1177 |
+
"3.1", "3.2","3.3")
|
1178 |
+
|
1179 |
+
for (index in report_indices) {
|
1180 |
+
tryCatch({
|
1181 |
+
report_data <- fetch_table_per_index(index)
|
1182 |
+
openxlsx::addWorksheet(wb, sheetName = paste("Reporte", index))
|
1183 |
+
openxlsx::writeData(wb, sheet = paste("Reporte", index), x = report_data)
|
1184 |
+
}, error = function(e) {
|
1185 |
+
print(paste("Error generating report", index, ":", e$message))
|
1186 |
+
})
|
1187 |
+
}
|
1188 |
+
|
1189 |
+
# Save the workbook
|
1190 |
+
openxlsx::saveWorkbook(wb, "exporte_reportes.xlsx", overwrite = TRUE)
|
1191 |
+
|
1192 |
+
.GlobalEnv[["EXPORT_STATE"]] <- TRUE
|
1193 |
+
exportado$se_exporto <- TRUE
|
1194 |
+
|
1195 |
+
# Optional: Show a message or log the successful export
|
1196 |
+
print("Reports exported successfully!")
|
1197 |
+
}
|
1198 |
+
})
|
1199 |
+
|
1200 |
}
|
1201 |
|
1202 |
# Run the application
|