|
library(magrittr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library(shiny)
|
|
options(shiny.maxRequestSize=30*1024^2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
source("dataframe extention.R")
|
|
source("Compute_YEI.R")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
talk_states=list(
|
|
"unauthenticated"="No has ingresado credenciales válidas aún",
|
|
"authenticated"="Estás autenticado y los reportes están listos para exportar"
|
|
)
|
|
|
|
CURRENT_STATE="unauthenticated"
|
|
EXPORT_STATE=FALSE
|
|
|
|
credentials.authenticate=function(
|
|
input_user,
|
|
input_pasword,
|
|
valid_credentials=data.frame(user="stockpesca", pasword="Temporal1843@!")
|
|
){
|
|
|
|
|
|
|
|
|
|
valid=
|
|
valid_credentials %>% dplyr::filter(user==input_user & pasword==input_pasword)
|
|
if (nrow(valid)>0)
|
|
{ .GlobalEnv[["CURRENT_STATE"]] ="authenticated"}
|
|
else {
|
|
.GlobalEnv[["CURRENT_STATE"]] ="unauthenticated"
|
|
}
|
|
|
|
print(.GlobalEnv[["CURRENT_STATE"]])
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
empty_table=data.frame(
|
|
data=c("No tiene permisos para ver esta tabla")
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inspecciones.cache=NULL
|
|
|
|
|
|
|
|
|
|
query_data=function(
|
|
file_path
|
|
){
|
|
if(.GlobalEnv[["CURRENT_STATE"]]=="unauthenticated"){
|
|
empty_table
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tryCatch({
|
|
data <- readxl::read_excel(file_path)
|
|
print("Archivo leído correctamente")
|
|
data
|
|
}, error = function(e) {
|
|
print("Error al leer el archivo:")
|
|
print(e$message)
|
|
data.frame(Mensaje = "Error al leer el archivo Excel")
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inspecciones.activas=function(
|
|
inspecciones
|
|
){
|
|
inspecciones %>%
|
|
|
|
dplyr::mutate(
|
|
activa=TRUE
|
|
) %>%
|
|
dplyr::filter(
|
|
activa
|
|
)
|
|
}
|
|
|
|
inspecciones.ensamblar_variables_de_reporte=function(
|
|
inspecciones
|
|
){
|
|
inspecciones %>%
|
|
dplyr::mutate(
|
|
ano=ANO_ZARPE,
|
|
mes=MES_ZARPE,
|
|
arte=ARTE,
|
|
sitio=SITIO,
|
|
fecha=paste(ANO_ZARPE, MES_ZARPE, DIA_ZARPE, sep="+" ),
|
|
horas_faena=HORA_FAENA
|
|
)
|
|
}
|
|
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas=
|
|
function(
|
|
Tabla_de_reporte
|
|
){
|
|
Tabla_de_reporte %>%
|
|
tidyr::pivot_wider(
|
|
names_from = mes,
|
|
names_prefix = "month_",
|
|
values_from = dplyr::last(names(.))
|
|
) %>%
|
|
Dataframe.order(
|
|
c( grep(names(.), pattern="^[^m]", value=TRUE),
|
|
paste("month_", 1:12, sep=""))
|
|
)
|
|
}
|
|
|
|
table_logic_per_index=list(
|
|
"1.1"=function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
|
|
split(paste(.$ano, .$mes, .$arte)) %>%
|
|
lapply(function(sub_df){
|
|
data.frame(
|
|
ano=dplyr::first(sub_df$ano),
|
|
mes=dplyr::first(sub_df$mes),
|
|
arte=dplyr::first(sub_df$arte),
|
|
reportada="(conteo) faenas activas",
|
|
faenas_activas=sub_df %>% nrow()
|
|
)
|
|
}) %>%
|
|
bind_rows() %>%
|
|
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
|
},
|
|
"1.2"=function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
|
|
split(paste(.$ano, .$mes, .$arte, .$sitio)) %>%
|
|
lapply(function(sub_df){
|
|
data.frame(
|
|
ano=dplyr::first(sub_df$ano),
|
|
mes=dplyr::first(sub_df$mes),
|
|
arte=dplyr::first(sub_df$arte),
|
|
sitio=dplyr::first(sub_df$sitio),
|
|
reportada="(conteo) faenas activas",
|
|
faenas_activas=sub_df %>% nrow()
|
|
)
|
|
}) %>%
|
|
bind_rows() %>%
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
|
},
|
|
"1.3"=function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
|
|
split(paste(.$ano, .$mes, .$arte, .$AREA, .$SUBAREA)) %>%
|
|
lapply(function(sub_df){
|
|
data.frame(
|
|
ano=dplyr::first(sub_df$ano),
|
|
mes=dplyr::first(sub_df$mes),
|
|
arte=dplyr::first(sub_df$arte),
|
|
area=dplyr::first(sub_df$AREA),
|
|
subarea=dplyr::first(sub_df$SUBAREA),
|
|
reportada="(conteo) faenas activas",
|
|
faenas_activas=nrow(sub_df)
|
|
)
|
|
}) %>%
|
|
bind_rows() %>%
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
|
},
|
|
"1.4"=function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
|
|
split(paste(.$ano, .$mes, .$arte)) %>%
|
|
lapply(function(sub_df){
|
|
data.frame(
|
|
ano=dplyr::first(sub_df$ano),
|
|
mes=dplyr::first(sub_df$mes),
|
|
arte=dplyr::first(sub_df$arte),
|
|
reportada="dias de actividad",
|
|
dias_actividad=length(unique(sub_df$fecha))
|
|
)
|
|
}) %>%
|
|
bind_rows() %>%
|
|
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
|
|
|
},
|
|
"1.5"=function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
|
|
split(paste(.$ano, .$mes, .$arte, .$sitio)) %>%
|
|
lapply(function(sub_df){
|
|
data.frame(
|
|
ano=dplyr::first(sub_df$ano),
|
|
mes=dplyr::first(sub_df$mes),
|
|
arte=dplyr::first(sub_df$arte),
|
|
sitio=dplyr::first(sub_df$sitio),
|
|
reportada="dias de actividad",
|
|
dias_actividad=length(unique(sub_df$fecha))
|
|
)
|
|
}) %>%
|
|
bind_rows() %>%
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
|
},
|
|
"1.6"=function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
|
|
split(paste(.$ano, .$mes, .$arte)) %>%
|
|
lapply(function(sub_df){
|
|
data.frame(
|
|
ano=dplyr::first(sub_df$ano),
|
|
mes=dplyr::first(sub_df$mes),
|
|
arte=dplyr::first(sub_df$arte),
|
|
reportada="(promedio) de las horas de faena x (1.3)",
|
|
horas_de_faena=round(mean(sub_df$horas_faena),3)*(1.3)
|
|
)
|
|
}) %>%
|
|
bind_rows() %>%
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
|
},
|
|
"1.7"=function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
|
|
split(paste(.$ano, .$mes, .$arte, .$AREA, .$SUBAREA )) %>%
|
|
lapply(function(sub_df){
|
|
data.frame(
|
|
ano=dplyr::first(sub_df$ano),
|
|
mes=dplyr::first(sub_df$mes),
|
|
arte=dplyr::first(sub_df$arte),
|
|
area=dplyr::first(sub_df$AREA),
|
|
subarea=dplyr::first(sub_df$SUBAREA),
|
|
reportada="(promedio) de las horas de faena x (1.3)",
|
|
horas_de_faena=round(mean(sub_df$horas_faena),3)*(1.3)
|
|
)
|
|
}) %>%
|
|
bind_rows() %>%
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
|
}
|
|
)
|
|
|
|
|
|
|
|
source("Compute_YEI.R")
|
|
|
|
table_logic_per_index[["2.1"]]=
|
|
function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
inspecciones.GROUP_BY.compute_yei(
|
|
GROUP_BY=c(
|
|
"ano" ,
|
|
"mes",
|
|
"CLASIFICAC",
|
|
"NOM_VULGAR"
|
|
)
|
|
) %>%
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
|
}
|
|
|
|
|
|
table_logic_per_index[["2.2"]]=
|
|
function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
inspecciones.GROUP_BY.compute_yei(
|
|
GROUP_BY=c(
|
|
"ano",
|
|
"mes",
|
|
"arte" ,
|
|
"GRUPO",
|
|
"SUBGRUPO"
|
|
)
|
|
) %>%
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
|
}
|
|
|
|
table_logic_per_index[["2.3"]]=
|
|
function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
inspecciones.GROUP_BY.compute_yei(
|
|
GROUP_BY=c(
|
|
"ano",
|
|
"mes",
|
|
|
|
"arte",
|
|
"sitio"
|
|
|
|
|
|
)
|
|
) %>%
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
|
}
|
|
|
|
table_logic_per_index[["2.4"]]=
|
|
function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
inspecciones.GROUP_BY.compute_yei(
|
|
GROUP_BY=c(
|
|
"ano",
|
|
"mes",
|
|
|
|
"arte",
|
|
"SUBGRUPO",
|
|
"NOM_VULGAR"
|
|
|
|
|
|
)
|
|
) %>%
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
|
}
|
|
|
|
|
|
table_logic_per_index[["2.5"]]=
|
|
function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
inspecciones.GROUP_BY.compute_yei(
|
|
GROUP_BY=c(
|
|
"ano",
|
|
"mes",
|
|
|
|
|
|
"arte",
|
|
"SUBGRUPO",
|
|
"NOM_VULGAR",
|
|
"AREA"
|
|
)
|
|
) %>%
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
|
}
|
|
|
|
table_logic_per_index[["2.6"]]=
|
|
function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
inspecciones.GROUP_BY.compute_yei(
|
|
GROUP_BY=c(
|
|
"ano",
|
|
"mes",
|
|
|
|
"arte",
|
|
"METODO",
|
|
|
|
"GRUPO",
|
|
"SUBGRUPO",
|
|
"NOM_VULGAR"
|
|
)
|
|
) %>%
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
|
}
|
|
|
|
table_logic_per_index[["2.7"]]=
|
|
function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
inspecciones.GROUP_BY.compute_yei(
|
|
GROUP_BY=c(
|
|
"ano",
|
|
"mes",
|
|
|
|
"arte",
|
|
"METODO",
|
|
|
|
"GRUPO",
|
|
"SUBGRUPO",
|
|
"NOM_VULGAR",
|
|
"AREA"
|
|
|
|
)
|
|
) %>%
|
|
tabla_de_reporte.formatear_ciclo_anual_en_columnas()
|
|
}
|
|
|
|
|
|
|
|
|
|
source("Compute_YEI.R")
|
|
|
|
inspecciones.ensamblar_captura_diaria=
|
|
function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
|
|
inspecciones.activas() %>%
|
|
inspecciones.ensamblar_variables_de_reporte() %>%
|
|
|
|
dplyr::transmute(
|
|
captura_total=CT_KG,
|
|
|
|
dia_zarpe=paste(ANO_ZARPE, MES_ZARPE , DIA_ZARPE, sep="/" ),
|
|
dia_arribo=paste(ANO_ARRIBO, MES_ARRIBO, DIA_ARRIBO, sep="/" ),
|
|
|
|
num_pescadores=PESCADORES,
|
|
|
|
arte_pesca=ARTE,
|
|
grupo=GRUPO
|
|
) %>%
|
|
dplyr::mutate(
|
|
dia_zarpe=as.Date(dia_zarpe),
|
|
dia_arribo=as.Date(dia_arribo)
|
|
) %>%
|
|
dplyr::mutate(
|
|
num_dias=as.numeric((dia_arribo-dia_zarpe)+1)
|
|
) %>%
|
|
dplyr::mutate(
|
|
captura_diaria=round( (captura_total/num_dias),4),
|
|
captura_diaria_por_pescador=round( ( (captura_total/num_dias)/num_pescadores ),4),
|
|
)
|
|
}
|
|
|
|
table_logic_per_index[["3.1"]]=
|
|
function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.ensamblar_captura_diaria() %>%
|
|
split(paste(.$arte_pesca,.$grupo)) %>%
|
|
lapply(function(sub_df){
|
|
data.frame(
|
|
|
|
mean_captura_diaria=round(mean(sub_df$captura_diaria, na.rm=TRUE),3),
|
|
sd_captura_diaria=round(sd(sub_df$captura_diaria, na.rm=TRUE), 3),
|
|
|
|
|
|
|
|
|
|
arte_pesca=dplyr::first(sub_df$arte_pesca),
|
|
grupo=dplyr::first(sub_df$grupo)
|
|
)
|
|
}) %>%
|
|
bind_rows()
|
|
}
|
|
|
|
|
|
table_logic_per_index[["3.2"]]=
|
|
function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.ensamblar_captura_diaria() %>%
|
|
split(paste(.$arte_pesca,.$grupo)) %>%
|
|
lapply(function(sub_df){
|
|
data.frame(
|
|
|
|
mean_captura_diaria_por_pescado=round(mean(sub_df$captura_diaria_por_pescador, na.rm=TRUE),3),
|
|
sd_captura_diaria_por_pescado=round(sd(sub_df$captura_diaria_por_pescador, na.rm=TRUE), 3),
|
|
|
|
|
|
|
|
|
|
arte_pesca=dplyr::first(sub_df$arte_pesca),
|
|
grupo=dplyr::first(sub_df$grupo)
|
|
)
|
|
}) %>%
|
|
bind_rows()
|
|
}
|
|
|
|
|
|
table_logic_per_index[["3.3"]]=
|
|
function(
|
|
inspecciones=inspecciones.cache
|
|
){
|
|
inspecciones %>%
|
|
inspecciones.ensamblar_captura_diaria() %>%
|
|
dplyr::mutate(
|
|
captura_diaria_por_pescador_por_hora = captura_diaria_por_pescador / 24
|
|
) %>%
|
|
split(paste(.$arte_pesca,.$grupo)) %>%
|
|
lapply(function(sub_df){
|
|
data.frame(
|
|
mean_captura_diaria_por_pescador_por_hora=round(mean(sub_df$captura_diaria_por_pescador_por_hora, na.rm=TRUE),3),
|
|
sd_captura_diaria_por_pescador_por_hora=round(sd(sub_df$captura_diaria_por_pescador_por_hora, na.rm=TRUE), 3),
|
|
|
|
arte_pesca=dplyr::first(sub_df$arte_pesca),
|
|
grupo=dplyr::first(sub_df$grupo)
|
|
)
|
|
}) %>%
|
|
bind_rows()
|
|
}
|
|
|
|
fetch_table_per_index=function(
|
|
index=1.1
|
|
){
|
|
table_logic_per_index[[index]]()
|
|
}
|
|
|
|
table.preview=function(
|
|
table,
|
|
max_rows=15,
|
|
max_cols=8
|
|
){
|
|
tryCatch({
|
|
table[1:min(max_rows, nrow(table) ), 1:min(max_cols, ncol(nrow(table)))]
|
|
},
|
|
error = function(e){empty_table})
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library(shiny)
|
|
ui = fluidPage(
|
|
|
|
|
|
column(3,
|
|
fluidRow(
|
|
wellPanel(
|
|
shiny::HTML("<p> Bienvenido a la <strong> aplicación pesquera </strong>. Escoja una acción </p>")
|
|
)),
|
|
fluidRow(
|
|
wellPanel(
|
|
shiny::tags$strong("Credenciales"),
|
|
shiny::textInput("usuario",
|
|
label=NULL,
|
|
placeholder = "inserte usuario",
|
|
width='100%'),
|
|
shiny::passwordInput("contrasena",
|
|
label=NULL,
|
|
placeholder = "inserte contrasena",
|
|
width='100%')
|
|
|
|
|
|
|
|
)),
|
|
|
|
fluidRow(
|
|
wellPanel(
|
|
|
|
fileInput('main_file_input', 'Seleccione un archivo desde su computador',
|
|
accept = c(".xlsx")
|
|
))),
|
|
|
|
fluidRow(
|
|
wellPanel(
|
|
|
|
shiny::tags$strong("Reportes"),
|
|
shiny::tags$br(),
|
|
shiny::actionButton("exportar_reportes",
|
|
"Exportar reportes",
|
|
width='100%'),
|
|
textOutput("export_result")
|
|
),
|
|
plotOutput(
|
|
"logo",
|
|
width = "100%",
|
|
height = "200px")
|
|
),
|
|
|
|
),
|
|
|
|
column(12-4,
|
|
|
|
offset = 1,
|
|
|
|
fluidRow(wellPanel(
|
|
shiny::tags$strong("Mensajes"),
|
|
textOutput("messages"))),
|
|
|
|
|
|
shiny::tags$strong("Pre-visualización de reportes"),
|
|
|
|
tabsetPanel(
|
|
|
|
tabPanel("0. Tabla maestra",
|
|
|
|
div(shiny::tableOutput("0_tabla_maestra"),
|
|
style = "font-size:50%")),
|
|
|
|
tabPanel("1. Esfuerzo",
|
|
|
|
tabsetPanel(
|
|
|
|
tabPanel(
|
|
"1.1",
|
|
div(shiny::tableOutput("1.1")),
|
|
style = "font-size:50%"),
|
|
|
|
tabPanel(
|
|
"1.2",
|
|
div(shiny::tableOutput("1.2")),
|
|
style = "font-size:50%"),
|
|
|
|
tabPanel(
|
|
"1.3",
|
|
div(shiny::tableOutput("1.3")),
|
|
style = "font-size:50%"
|
|
),
|
|
|
|
tabPanel(
|
|
"1.4",
|
|
div(shiny::tableOutput("1.4")),
|
|
style = "font-size:50%"),
|
|
|
|
tabPanel(
|
|
"1.5",
|
|
div(shiny::tableOutput("1.5")),
|
|
style = "font-size:50%"),
|
|
|
|
tabPanel(
|
|
"1.6",
|
|
div(shiny::tableOutput("1.6")),
|
|
style = "font-size:50%"),
|
|
|
|
tabPanel(
|
|
"1.7",
|
|
div(shiny::tableOutput("1.7")),
|
|
style = "font-size:50%")
|
|
)),
|
|
|
|
tabPanel("2. Captura total",
|
|
|
|
tabsetPanel(
|
|
|
|
tabPanel(
|
|
"2.1",
|
|
div(shiny::tableOutput("2.1")),
|
|
style = "font-size:50%"),
|
|
|
|
tabPanel(
|
|
"2.2",
|
|
div(shiny::tableOutput("2.2")),
|
|
style = "font-size:50%"),
|
|
|
|
tabPanel(
|
|
"2.3",
|
|
div(shiny::tableOutput("2.3")),
|
|
style = "font-size:50%"),
|
|
|
|
tabPanel(
|
|
"2.4",
|
|
div(shiny::tableOutput("2.4")),
|
|
style = "font-size:50%"),
|
|
|
|
tabPanel(
|
|
"2.5",
|
|
div(shiny::tableOutput("2.5")),
|
|
style = "font-size:50%"),
|
|
|
|
tabPanel(
|
|
"2.6",
|
|
div(shiny::tableOutput("2.6")),
|
|
style = "font-size:50%"),
|
|
|
|
tabPanel(
|
|
"2.7",
|
|
div(shiny::tableOutput("2.7")),
|
|
style = "font-size:50%")
|
|
)),
|
|
|
|
tabPanel("3. CPUE",
|
|
|
|
tabsetPanel(
|
|
|
|
tabPanel(
|
|
"3.1",
|
|
div(shiny::tableOutput("3.1")),
|
|
style = "font-size:50%"),
|
|
|
|
tabPanel(
|
|
"3.2",
|
|
div(shiny::tableOutput("3.2")),
|
|
style = "font-size:50%"),
|
|
|
|
tabPanel(
|
|
"3.3",
|
|
div(shiny::tableOutput("3.3")),
|
|
style = "font-size:50%")))
|
|
|
|
|
|
)))
|
|
|
|
|
|
|
|
index.managed_table=function(
|
|
index,
|
|
input
|
|
){
|
|
if(is.null(input$main_file_input) || CURRENT_STATE=="unauthenticated"){
|
|
empty_table
|
|
} else {
|
|
tryCatch({
|
|
fetch_table_per_index(index) %>%
|
|
table.preview()
|
|
}, error = function(e) {
|
|
empty_table
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
server = function(input, output) {
|
|
|
|
|
|
usuario=reactive({input$usuario})
|
|
contrasena=reactive({input$contrasena})
|
|
exportar=reactive({input$exportar_reportes})
|
|
exportado=reactiveValues(
|
|
se_exporto=FALSE
|
|
)
|
|
actualizar_mensaje_exportado=reactive({
|
|
exportado
|
|
})
|
|
|
|
|
|
output$"0_tabla_maestra" = renderTable({
|
|
|
|
credentials.authenticate(input$usuario, input$contrasena)
|
|
print("Autenticado")
|
|
|
|
file_path_ = input$main_file_input$datapath
|
|
|
|
print("Path")
|
|
print(file_path_)
|
|
|
|
data <- query_data(file_path = file_path_)
|
|
|
|
inspecciones.cache <<- data
|
|
loaded_data(data)
|
|
data %>%
|
|
table.preview()
|
|
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
|
|
loaded_data <- reactiveVal(NULL)
|
|
|
|
|
|
observeEvent(input$main_file_input, {
|
|
file_path_ <- input$main_file_input$datapath
|
|
data <- query_data(file_path = file_path_)
|
|
inspecciones.cache <<- data
|
|
loaded_data(data)
|
|
})
|
|
|
|
authenticated <- reactive({
|
|
credentials.authenticate(input$usuario, input$contrasena)
|
|
return(.GlobalEnv[["CURRENT_STATE"]] == "authenticated")
|
|
})
|
|
|
|
output$"1.1" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("1.1")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover = TRUE,
|
|
bordered = TRUE,
|
|
width = '100%',
|
|
spacing = "s"
|
|
)
|
|
output$"1.2" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("1.2")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
|
|
output$"1.3" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("1.3")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
|
|
output$"1.4" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("1.4")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
output$"1.5" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("1.5")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
output$"1.6" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("1.6")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
output$"1.7" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("1.7")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
output$"2.1" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("2.1")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
output$"2.2" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("2.2")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
output$"2.3" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("2.3")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
output$"2.4" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("2.4")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
output$"2.5" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("2.5")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
output$"2.6" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("2.6")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
output$"2.7" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("2.7")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
|
|
output$"3.1" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("3.1")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
output$"3.2" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("3.2")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
output$"3.3" = renderTable({
|
|
if (authenticated()) {
|
|
print(paste("User is authenticated, showing results..."))
|
|
data <- fetch_table_per_index("3.3")
|
|
data
|
|
} else {
|
|
print(paste("User is not authenticated, returning error message..."))
|
|
"No tiene permisos para ver esta tabla"
|
|
}
|
|
},
|
|
striped = TRUE,
|
|
hover=TRUE,
|
|
bordered=TRUE,
|
|
width='100%',
|
|
spacing="s"
|
|
)
|
|
|
|
output$"export_result"=renderText({
|
|
actualizar_mensaje_exportado()
|
|
ifelse(exportado$se_exporto==TRUE, "Felicidades! El reporte fue exportado", "Aún no has exportado el reporte")
|
|
})
|
|
|
|
observeEvent(input$exportar_reportes,{
|
|
if (.GlobalEnv[["CURRENT_STATE"]] == "authenticated") {
|
|
|
|
setwd(PROYECT_HOME)
|
|
if (!dir.exists("reportes")) {
|
|
dir.create("reportes")
|
|
}
|
|
setwd("reportes")
|
|
|
|
|
|
wb <- openxlsx::createWorkbook()
|
|
|
|
|
|
report_indices <- c("1.1", "1.2","1.3", "1.4", "1.5", "1.6", "1.7",
|
|
"2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7",
|
|
"3.1", "3.2","3.3")
|
|
|
|
for (index in report_indices) {
|
|
tryCatch({
|
|
report_data <- fetch_table_per_index(index)
|
|
openxlsx::addWorksheet(wb, sheetName = paste("Reporte", index))
|
|
openxlsx::writeData(wb, sheet = paste("Reporte", index), x = report_data)
|
|
}, error = function(e) {
|
|
print(paste("Error generating report", index, ":", e$message))
|
|
})
|
|
}
|
|
|
|
|
|
openxlsx::saveWorkbook(wb, "exporte_reportes.xlsx", overwrite = TRUE)
|
|
|
|
.GlobalEnv[["EXPORT_STATE"]] <- TRUE
|
|
exportado$se_exporto <- TRUE
|
|
|
|
|
|
print("Reports exported successfully!")
|
|
}
|
|
})
|
|
|
|
}
|
|
|
|
|
|
shinyApp(ui = ui, server = server)
|
|
|
|
|