pacman::p_load(
# Interactivo
shiny,
flexdashboard,
leaflet,
# Tablas
reactable,
# Gráficos
scico,
apyramid,
# Mapas
geoAr,
sf,
# Manejo datos
rio,
janitor,
tidyverse
)Reporte Epidemiológico SI.VI.LE 2024
#|id: Cargar datos SIVILE
datos <- import("clean/datos_sivile_2024.csv") |>
mutate(across(
.cols = where(is.character) | codigo_institucion_id,
.fns = ~ factor(.x)
))shp_prov <- get_geo("ARGENTINA") |>
# Agrupar provincias
count(codprov_censo) |>
# Validar geometría
st_make_valid() |>
# Añadir códigos provincia
left_join(
show_arg_codes() |>
# id provincia a numérico
mutate(codprov = parse_number(codprov)) |>
# Filtrar totales
filter(between(codprov, 1, 24))
) |>
# Seleccionar columnas
select(codprov_censo, id, prov_lesion_id = codprov, prov_lesion = name_iso) |>
# Añadir frecuencias por sexo
left_join(
datos |>
tabyl(prov_lesion, sexo)
) |>
# Añadir frecuencias por edad
left_join(
datos |>
tabyl(prov_lesion, grupo_edad) |>
adorn_totals(where = "col")
)Joining with `by = join_by(codprov_censo)`
Joining with `by = join_by(prov_lesion)`
Joining with `by = join_by(prov_lesion)`
UCL
Columna_1
UCL SIVILE ACTIVAS
valueBox(
value = nlevels(datos$codigo_institucion_id),
icon = "fa-hospital-o"
)
27
Registros totales
valueBox(
value = nrow(read_delim(
"raw/export_Sistema_de_Vigilancia_de_Lesiones_SIVILE_Completo_2024.txt"
)),
icon = "fa-file-text"
)Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
dat <- vroom(...)
problems(dat)
Rows: 12180 Columns: 126
── Column specification ────────────────────────────────────────────────────────
Delimiter: "\t"
chr (83): DG4_FECHA_CONSULTA, DG6_FECHA_REPORTE_SISA, DG8_ENTREVISTADOR, DG9...
dbl (42): DG1_CODIGO_INSTITUCION_ID, DG2_SERVICIO_ID, DG3_NUMERO_CASO, DG5_H...
lgl (1): DG3A_NRO_CASO_INSTITUCION
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
12180
Registros válidos1
valueBox(value = nrow(datos), icon = "fa-file-text")
11053
Tabla
# Crear tabla
datos |>
tabyl(codigo_institucion_id) |>
arrange(-n) |>
adorn_pct_formatting() |>
rename(UCL = codigo_institucion_id, Frecuencia = n, "%" = percent) |>
# Opciones interactivas
reactable(
pageSizeOptions = c(10, 25, 50),
resizable = TRUE,
compact = TRUE,
highlight = TRUE,
bordered = TRUE,
striped = TRUE,
showSortable = TRUE,
showPageSizeOptions = TRUE
)Provincia
Mapa
Distribución de lesiones por causas externas por provincia
## Variables
vars <- c(
"Total",
"Femenino",
"Masculino",
"0-1 años",
"2-4 años",
"5-9 años",
"10-14 años",
"15-24 años",
"25-44 años",
"45-64 años",
"65+ años"
)
## Crear paleta global con el rango de todas las variables
pal <- colorNumeric(
palette = scico(n = 10, palette = "tokyo", direction = -1),
domain = c(0, max(shp_prov$Total, na.rm = TRUE))
)
## Crear mapa interactivo
shp_prov |>
leaflet() |>
# Mapa base
addProviderTiles("CartoDB.PositronNoLabels") |>
(\(mapa) {
# Agregar todas las capas
for (var in vars) {
mapa <- mapa |>
addPolygons(
fillColor = ~ pal(get(var)),
color = "grey",
weight = 1,
opacity = 0.5,
fillOpacity = 0.7,
group = var
)
}
mapa
})() |>
# Control de capas
addLayersControl(
baseGroups = c("Mapa base"),
overlayGroups = vars
) |>
hideGroup(vars[-1]) |>
showGroup("Total") |>
# Añadir leyenda global
addLegend(
pal = pal,
values = shp_prov$Total,
title = "Frecuencia",
# na.label = "Sin datos",
position = "bottomright"
)Tabla
Frecuencia de lesiones por causas externas por provincia
# Dataset para la tabla
datos_prov <- datos |>
select(
Provincia = prov_lesion,
Sexo = sexo,
Edad = grupo_edad,
Mecanismo = mecanismo_cat,
Intencionalidad = intencionalidad_cat
)
## Selector de variables
ui <- fluidPage(
checkboxGroupInput(
inputId = "vars",
label = "Variables:",
choices = names(datos_prov)[-1],
inline = TRUE
),
reactableOutput("tabla")
)
## Tabla
server <- function(input, output, session) {
output$tabla <- renderReactable({
# Variables a agrupar
vars <- c("Provincia", input$vars)
# Calcular frecuencias y porcentaje
datos_prov |>
count(across(all_of(vars))) |>
mutate(pct = round(n / sum(n) * 100, 2)) |>
# Crear tabla reactable
reactable(
columns = list(
n = colDef(name = "Frecuencia"),
pct = colDef(name = "%")
),
pageSizeOptions = c(10, 25, 50),
filterable = TRUE,
defaultPageSize = 20,
compact = TRUE,
highlight = TRUE,
bordered = TRUE,
striped = TRUE,
showSortable = TRUE,
showPageSizeOptions = TRUE
)
})
}
## Mostrar tabla
shinyApp(ui, server)Footnotes
Datos completos para sexo, edad, provincia de ocurrencia y mecanismo de la lesión↩︎