Skip to content

Commit

Permalink
Mejora la estructura de la app
Browse files Browse the repository at this point in the history
Agrega primeras carpeta de test - renombra modulos como mod_* - separa una funcion que formatea fechas que se repite en todos los modulos para mejorar el testeo - remueve parte del data wrangling fuera del modulo de mapa_covid_departamentos - agrega github action R CMD check que estaba en falta - Agrega badge de lifecycle experimental
  • Loading branch information
flor14 committed Dec 22, 2023
1 parent 9ab455e commit acd313f
Show file tree
Hide file tree
Showing 46 changed files with 290 additions and 93 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.github$
_\.new\.png$
29 changes: 29 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
.Ruserdata
data/
.DS_Store
inst/rasters/
inst/rasters/
# {shinytest2}: Ignore new debug snapshots for `$expect_values()`
*_.new.png
4 changes: 4 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ Imports:
Depends:
R (>= 2.10)
LazyData: true
Suggests:
shinytest2,
testthat (>= 3.0.0)
Config/testthat/edition: 3
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export(Partidos_Server)
export(Partidos_UI)
export(ReporteServer)
export(ReporteUI)
export(runapp)
export(formatted_date)
export(run_app)
export(server)
export(ui)
importFrom(shiny,shinyApp)
54 changes: 54 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#' bsas: Partidos de Buenos Aires
#'
#' Dataset de clase sf con los polígonos de los partidos de Buenos Aires y
#' las coordenadas de la bounding box de cada uno. Ver el repositorio de
#' GeoCovid BsAs para mas detalle de estas Variables
#'
#' @format ## `bsas`
#' Este
#' \describe{
#' \item{partido}{Nombre del partido de prov de Buenos Aires}
#' \item{lat1}{Latitud}
#' \item{lat2}{Latitud}
#' \item{lng1}{Longitud}
#' \item{lng2}{Longitud}
#' \item{geom}{sfc_POLYGON}
#' }
"bsas"

#' mini_data_sisa_deploy: Extrato del dataset de casos de COVID-19
#'
#' Ver el repositorio de GeoCovid BsAs para mas detalle de estas Variables
#'
#' @format ## `mini_data_sisa_deploy`
#' Una extracto de la abse de datos con 2230 filas y 4 columnas:
#' \describe{
#' \item{id_evento_caso}{ID}
#' \item{residencia_provincia_nombre}{Provincia}
#' \item{residencia_departamento_nombre}{Departamento, partido}
#' \item{fecha_enfermo}{Fecha reporte caso COVID-19}
#' }
"mini_data_sisa_deploy"

#' px_baires: Valores promedio de movilidad ciudadana por partido
#'
#' Ver el repositorio de GeoCovid BsAs para mas detalle de estas Variables.
#' Se esta empleando solo un extracto de la base de datos para este dataset de
#' ejempplo.
#'
#' @format ## `px_baires`
#' Una extracto de la abse de datos con 4080 filas y 11 columnas:
#' \describe{
#' \item{fecha}{ID}
#' \item{locacion}{Provincia}
#' \item{tipo_de_raster}{Cambio porcentual prepandemia (pc) o semanal (7dpc)}
#' \item{partido}{Partido o departamento}
#' \item{noche_0}{Promedio para el raster de la noche}
#' \item{mañana_8}{Promedio para el raster de la mañana}
#' \item{tarde_16}{Promedio para el raster de la tarde}
#' \item{px_mean_dianoche}{Promedio para los rasters de mañana y tarde}
#' \item{criterio}{Vuelve variable categorica px_mean_dianoche}
#' \item{criterio_noche}{Vuelve variable categorica noche_0}
#' \item{geom}{sfc_POLYGON}
#' }
"px_baires"
21 changes: 21 additions & 0 deletions R/fun_conversion_fecha.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' Convierte el formato de la fecha de %Y-%m-%dT%H:%M:%S a "%Y-%m-%d"
#'
#' @param fecha Fecha
#'
#' @return Fecha en formato "%Y-%m-%d"
#' @export
#'
#' @examples
#'
#' formatted_date("2020-05-10T07:00:00.000Z")
#'
formatted_date <- function(fecha){

# Conservo solo la fecha
parsed_date <- lubridate::ymd_hms(fecha)

# Format the date to "YYYY-MM-DD" format
formatted_date <- format(parsed_date, format = "%Y-%m-%d")

formatted_date
}
2 changes: 1 addition & 1 deletion R/config.R → R/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ base_raster <- all_files[grep(".tif$",



# Define an alias 'images' for the directory 'inst/www/images'
# Permite leer el directorio imagenes dentro de www/'
shiny::addResourcePath(prefix = "imagenes",
directoryPath = system.file("www/imagenes",
package = "geocovidapp"))
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 3 additions & 8 deletions R/histograma_raster.R → R/mod_histograma_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,9 @@ HistogramaRaster_Server <- function(id,
formatted_date <- format("2020-05-03", format = "%Y-%m-%d")
}else{

# Fecha original
original_date <- fecha()

# convierto a formato fecha
parsed_date <- lubridate::ymd_hms(original_date)


# Convierto a formato "YYYY-MM-DD"
formatted_date <- format(parsed_date, format = "%Y-%m-%d")
formatted_date <- formatted_date(fecha())

}

Expand Down Expand Up @@ -138,7 +133,7 @@ raster_hist <- reactive({

output$histograma <- renderPlot({
par(mar=c(4,1,3,1)) # bottom, left, top, right
print(terra::values(raster_hist()))

hist(terra::values(raster_hist()),
breaks = c(50, 40, 30 ,
20 , 10, 1, -1,
Expand Down
File renamed without changes.
53 changes: 8 additions & 45 deletions R/mapa_covid_departamentos.R → R/mod_mapa_covid_departamentos.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ base::colnames(px_baires)[2] <- as.character("Noche")

})

formatted_date <- shiny::reactive({
fecha_formato <- shiny::reactive({

# Agrego un dia por default para que renderice si no hay otras fechas.
if(is.null(fechas$casos_covid())){
Expand All @@ -186,10 +186,8 @@ base::colnames(px_baires)[2] <- as.character("Noche")


}else{

parsed_date <- lubridate::ymd_hms(fechas$casos_covid())

format(parsed_date, format = "%Y-%m-%d")
fecha = fechas$casos_covid()
formatted_date(fecha = fecha)

}

Expand All @@ -201,7 +199,7 @@ base::colnames(px_baires)[2] <- as.character("Noche")
paste('Movilidad ciudadana',
if(input$tipo_tab == 'pc'){ 'prepandemia'}else{ 'semanal'},
'para', if(input$momento == 'criterio'){ 'el promedio mañana y tarde'}else{ 'la noche'},
'de', format(formatted_date(), format = "%d-%m-%Y"))
'de', format(fecha_formato(), format = "%d-%m-%Y"))
})

# Datos de casos de COVID para el bubble map
Expand All @@ -211,7 +209,7 @@ base::colnames(px_baires)[2] <- as.character("Noche")

comunas <- data_sisa |>
dplyr::filter(residencia_provincia_nombre == 'CABA' &
fecha_enfermo == formatted_date()) |>
fecha_enfermo == fecha_formato()) |>
dplyr::group_by(residencia_provincia_nombre) |>
dplyr::summarize(n_casos = dplyr::n()) |>
dplyr::rename('partido' = residencia_provincia_nombre )
Expand All @@ -220,7 +218,7 @@ base::colnames(px_baires)[2] <- as.character("Noche")

casos_diarios <- dplyr::filter(data_sisa,
residencia_provincia_nombre == 'Buenos Aires' &
fecha_enfermo == formatted_date() ) |> #combino horarios
fecha_enfermo == fecha_formato() ) |> #combino horarios
dplyr::group_by(residencia_departamento_nombre) |>
dplyr::summarize(n_casos = dplyr::n()) |>
dplyr::rename(partido = residencia_departamento_nombre) |>
Expand Down Expand Up @@ -262,44 +260,9 @@ base::colnames(px_baires)[2] <- as.character("Noche")

# st_read('data/rasters/px_baires.gpkg')
px_baires |>
dplyr::filter(fecha == formatted_date(),
dplyr::filter(fecha == fecha_formato(),
tipo_de_raster == input$tipo_tab
) |>
dplyr::mutate(criterio = dplyr::case_when(px_mean_dianoche > 40 ~ "mas de 40",
40 > px_mean_dianoche & px_mean_dianoche > 30 ~ "40 - 30",
30 > px_mean_dianoche & px_mean_dianoche > 20 ~ "30 - 20",
20 > px_mean_dianoche & px_mean_dianoche > 10 ~ "20 - 10",
10 > px_mean_dianoche & px_mean_dianoche > 1 ~ "10 - 1",
1 > px_mean_dianoche & px_mean_dianoche> -1 ~ "sin cambios",
-1 > px_mean_dianoche& px_mean_dianoche > -10 ~ "-1 - -10",
-10 > px_mean_dianoche& px_mean_dianoche > -20 ~ "-10 - -20",
-20 > px_mean_dianoche& px_mean_dianoche > -30 ~ "-20 - -30",
-30 > px_mean_dianoche& px_mean_dianoche > -40 ~ "-30 - -40",
-40 > px_mean_dianoche ~ "menor a -40"),
criterio_noche = dplyr::case_when(noche_0 > 40 ~ "mas de 40",
40 > noche_0 & noche_0 > 30 ~ "40 - 30",
30 > noche_0 & noche_0 > 20 ~ "30 - 20",
20 > noche_0 & noche_0 > 10 ~ "20 - 10",
10 > noche_0 & noche_0 > 1 ~ "10 - 1",
1 > noche_0 & noche_0> -1 ~ "sin cambios",
-1 > noche_0 & noche_0 > -10 ~ "-1 - -10",
-10 > noche_0 & noche_0 > -20 ~ "-10 - -20",
-20 > noche_0 & noche_0 > -30 ~ "-20 - -30",
-30 > noche_0 & noche_0 > -40 ~ "-30 - -40",
-40 > noche_0 ~ "menor a -40")) |>
dplyr::mutate(criterio = forcats::fct_relevel(criterio, c("mas de 40", "40 - 30",
"30 - 20","20 - 10","10 - 1",
"sin cambios",
"-1 - -10", "-10 - -20",
"-20 - -30", "-30 - -40",
"menor a -40")),
criterio_noche = forcats::fct_relevel(criterio_noche, c("mas de 40", "40 - 30",
"30 - 20","20 - 10","10 - 1",
"sin cambios",
"-1 - -10", "-10 - -20",
"-20 - -30", "-30 - -40",
"menor a -40"))) |> sf::st_as_sf()

)
})

burbujas_plot <- shiny::reactive({
Expand Down
File renamed without changes.
8 changes: 1 addition & 7 deletions R/mapa_partido.R → R/mod_mapa_partido.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,8 @@ MapaPartido_Server <- function(id,
}else{


# Original date string
original_date <- fecha()

# Parse the original date string
parsed_date <- ymd_hms(original_date)

# Format the date to "YYYY-MM-DD" format
formatted_date <- format(parsed_date, format = "%Y-%m-%d") }
formatted_date <- formatted_date(fecha()) }



Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions R/reporte.R → R/mod_reporte.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ ReporteServer <- function(id,
formatted_date <- format(fecha, format = "%Y-%m-%d")
formatted_date
}else{
fecha = fecha()
parsed_date <- lubridate::ymd_hms()
formatted_date <- format(parsed_date, format = "%Y-%m-%d")
formatted_date}

formatted_date <- formatted_date(fecha())
formatted_date
}
})


Expand Down
4 changes: 2 additions & 2 deletions R/geocovidapp.R → R/run_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#'
#' @examples
#' \dontrun{
#' runapp()
#' run_app()
#' }
runapp <- function() {
run_app <- function() {

shiny::shinyApp(ui = ui, server = server)
}
1 change: 1 addition & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ knitr::opts_chunk$set(
<!-- badges: start -->

[![R-CMD-check](https://github.com/Fernandez-Lab-WSU/geocovid_app/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Fernandez-Lab-WSU/geocovid_app/actions/workflows/R-CMD-check.yaml)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->

ESTE PAQUETE SE ENCUENTRA EN REVISION.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
<!-- badges: start -->

[![R-CMD-check](https://github.com/Fernandez-Lab-WSU/geocovid_app/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Fernandez-Lab-WSU/geocovid_app/actions/workflows/R-CMD-check.yaml)
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->

ESTE PAQUETE SE ENCUENTRA EN REVISION Y LA APP DISPONIBLE ES UNA VERSION PRELIMINAR.
ESTE PAQUETE SE ENCUENTRA EN REVISION. ES UNA VERSION PRELIMINAR.

## Instalación

Expand Down
2 changes: 1 addition & 1 deletion man/Dygraph_Server.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/Dygraph_UI.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/FechaMomentoUI.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/FechaMomento_Server.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/HistogramaRaster_Server.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/HistogramaRaster_UI.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/MapaBaires_Server.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/MapaBaires_UI.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/MapaCovidDepartamentos_Server.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit acd313f

Please sign in to comment.