From 2107932b3d2974a040636afd6bd3575495fdc018 Mon Sep 17 00:00:00 2001 From: plablo09 Date: Tue, 18 May 2021 12:48:39 -0500 Subject: [PATCH 01/13] Cambia directorio de cache en docker. --- Dockerfile | 8 ++++---- dev/run_dev.R | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index e5c144d..da2f6c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,10 +24,10 @@ RUN apt-get update && \ apt-get clean RUN R -e "install.packages('devtools', repos = 'http://cran.us.r-project.org')" -RUN R -e "devtools::install_github('CentroGeo/visualizadorIncidentesViales', force=TRUE)" +RUN R -e "devtools::install_github('CentroGeo/visualizadorIncidentesViales', force=TRUE, ref = 'fix_cache_bugs')" ###Make dir for cache -RUN mkdir ./cache_dir +RUN mkdir /cache_dir # expose port EXPOSE 3838 @@ -35,8 +35,8 @@ EXPOSE 3838 CMD ["R", "-e", \ "options('shiny.port'=3838,shiny.host='0.0.0.0'); \ options('Actualizar_datos' = TRUE); \ - options('Cache_dir'='./cache_dir');\ - options('Cache_DB_dir'='./cache_dir');\ + options('Cache_dir'='/cache_dir');\ + options('Cache_DB_dir'='/cache_dir');\ library(visualizadorIncidentesViales); \ visualizadorIncidentesViales::run_app()"] # CMD ["R", "-e", \ diff --git a/dev/run_dev.R b/dev/run_dev.R index 2202fc6..2ed20a3 100644 --- a/dev/run_dev.R +++ b/dev/run_dev.R @@ -5,8 +5,8 @@ options(shiny.maxRequestSize = 510 * 1024^2) shinyOptions(cache = memoryCache(size = 20e7)) options("Actualizar_datos" = TRUE) -options("Cache_dir" = "./cache_vis") -options("Cache_DB_dir" = "./cache_vis") +options("Cache_dir" = "./cache_dir") +options("Cache_DB_dir" = "./cache_dir") # Detach all loaded packages and clean your environment golem::detach_all_attached() From 5119adac00e1e51f8e280421f97ed63dacb4633a Mon Sep 17 00:00:00 2001 From: plablo09 Date: Tue, 18 May 2021 14:16:53 -0500 Subject: [PATCH 02/13] Cambios al cache. --- Dockerfile | 6 +++--- R/mod_DBSelector.R | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index da2f6c4..cf67685 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,7 @@ RUN R -e "install.packages('devtools', repos = 'http://cran.us.r-project.org')" RUN R -e "devtools::install_github('CentroGeo/visualizadorIncidentesViales', force=TRUE, ref = 'fix_cache_bugs')" ###Make dir for cache -RUN mkdir /cache_dir +RUN mkdir ./cache_dir # expose port EXPOSE 3838 @@ -35,8 +35,8 @@ EXPOSE 3838 CMD ["R", "-e", \ "options('shiny.port'=3838,shiny.host='0.0.0.0'); \ options('Actualizar_datos' = TRUE); \ - options('Cache_dir'='/cache_dir');\ - options('Cache_DB_dir'='/cache_dir');\ + options('Cache_dir'='./cache_dir');\ + options('Cache_DB_dir'='./cache_dir');\ library(visualizadorIncidentesViales); \ visualizadorIncidentesViales::run_app()"] # CMD ["R", "-e", \ diff --git a/R/mod_DBSelector.R b/R/mod_DBSelector.R index f632a14..6e38a92 100644 --- a/R/mod_DBSelector.R +++ b/R/mod_DBSelector.R @@ -91,6 +91,7 @@ filtra_datos <- function(datos_filtrados, # Esta sólo se encarga de que exista el objeto cache fc <- function(cache_selected = "./cache_dir") { + dir.create(cache_selected, showWarnings = FALSE) fc_c <- memoise::cache_filesystem(cache_selected) print(paste("Path for DB cache Storage: ", cache_selected)) From 8b2b2a424046ba668b7709c24ac782ca101824af Mon Sep 17 00:00:00 2001 From: plablo09 Date: Tue, 18 May 2021 16:06:50 -0500 Subject: [PATCH 03/13] =?UTF-8?q?Versiones=20librer=C3=ADas.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DESCRIPTION | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7aec58a..92f7d85 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,7 @@ License: MIT + file LICENSE Imports: config, golem, - shiny, + shiny(==1.5.0), processx, attempt, DT, @@ -37,7 +37,8 @@ Imports: leaflet.extras, janitor, magrittr, - memoise + memoise(==1.1.0), + cachem Encoding: UTF-8 LazyData: true RoxygenNote: 7.1.1 From 93b64cf03d2a31b23a24e27c28bfc6a8f918e7b6 Mon Sep 17 00:00:00 2001 From: plablo09 Date: Tue, 18 May 2021 16:23:42 -0500 Subject: [PATCH 04/13] Mas versiones de paquetes. --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 92f7d85..f3e655f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,7 @@ License: MIT + file LICENSE Imports: config, golem, - shiny(==1.5.0), + shiny(<=1.5.0), processx, attempt, DT, @@ -37,7 +37,7 @@ Imports: leaflet.extras, janitor, magrittr, - memoise(==1.1.0), + memoise(<=1.1.0), cachem Encoding: UTF-8 LazyData: true From 3c60c048611af98b8ada74b538cf6118d7abd518 Mon Sep 17 00:00:00 2001 From: pablo lopez Date: Tue, 18 May 2021 16:35:09 -0500 Subject: [PATCH 05/13] Update DESCRIPTION --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f3e655f..d9148d9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,7 @@ License: MIT + file LICENSE Imports: config, golem, - shiny(<=1.5.0), + shiny(<= 1.5.0), processx, attempt, DT, @@ -37,7 +37,7 @@ Imports: leaflet.extras, janitor, magrittr, - memoise(<=1.1.0), + memoise(<= 1.1.0), cachem Encoding: UTF-8 LazyData: true From 68bbe4a091ccb72008eb609f55f6276d4a4800f1 Mon Sep 17 00:00:00 2001 From: plablo09 Date: Wed, 19 May 2021 09:10:25 -0500 Subject: [PATCH 06/13] No crear directorio de cache. --- R/mod_DBSelector.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/mod_DBSelector.R b/R/mod_DBSelector.R index 6e38a92..fd47c20 100644 --- a/R/mod_DBSelector.R +++ b/R/mod_DBSelector.R @@ -91,8 +91,6 @@ filtra_datos <- function(datos_filtrados, # Esta sólo se encarga de que exista el objeto cache fc <- function(cache_selected = "./cache_dir") { - - dir.create(cache_selected, showWarnings = FALSE) fc_c <- memoise::cache_filesystem(cache_selected) print(paste("Path for DB cache Storage: ", cache_selected)) return (fc_c) From 3f56f91edf985e083667d80e7d0ae1419e3ac3f6 Mon Sep 17 00:00:00 2001 From: plablo09 Date: Wed, 19 May 2021 09:10:52 -0500 Subject: [PATCH 07/13] =?UTF-8?q?Instala=20la=20aplicaci=C3=B3n=20del=20di?= =?UTF-8?q?rectorio=20local.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index cf67685..16555a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,11 +23,14 @@ RUN apt-get update && \ apt-get upgrade -y && \ apt-get clean +RUN mkdir /visualizadorIncidentesViales RUN R -e "install.packages('devtools', repos = 'http://cran.us.r-project.org')" -RUN R -e "devtools::install_github('CentroGeo/visualizadorIncidentesViales', force=TRUE, ref = 'fix_cache_bugs')" +ADD ./ /visualizadorIncidentesViales/ +RUN R -e "devtools::install_local('/visualizadorIncidentesViales')" +#RUN R -e "devtools::install_github('CentroGeo/visualizadorIncidentesViales', force=TRUE, ref = 'fix_cache_bugs')" ###Make dir for cache -RUN mkdir ./cache_dir +RUN mkdir /cache_dir # expose port EXPOSE 3838 @@ -35,8 +38,8 @@ EXPOSE 3838 CMD ["R", "-e", \ "options('shiny.port'=3838,shiny.host='0.0.0.0'); \ options('Actualizar_datos' = TRUE); \ - options('Cache_dir'='./cache_dir');\ - options('Cache_DB_dir'='./cache_dir');\ + options('Cache_dir'='/cache_dir');\ + options('Cache_DB_dir'='/cache_dir');\ library(visualizadorIncidentesViales); \ visualizadorIncidentesViales::run_app()"] # CMD ["R", "-e", \ From 6f3dabc90a6501a75d7bbc9403e714e63b7bc1ff Mon Sep 17 00:00:00 2001 From: plablo09 Date: Wed, 19 May 2021 09:14:24 -0500 Subject: [PATCH 08/13] Quitar versiones de las dependencias. --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d9148d9..b93e8fa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,7 @@ License: MIT + file LICENSE Imports: config, golem, - shiny(<= 1.5.0), + shiny, processx, attempt, DT, @@ -37,7 +37,7 @@ Imports: leaflet.extras, janitor, magrittr, - memoise(<= 1.1.0), + memoise, cachem Encoding: UTF-8 LazyData: true From e2ce0e8369b2064564aba6853e05c6b8659d0fa5 Mon Sep 17 00:00:00 2001 From: plablo09 Date: Wed, 19 May 2021 12:57:08 -0500 Subject: [PATCH 09/13] Usa bindCache de shiny para la base de datos. --- R/mod_DBSelector.R | 37 ++++++++++++++++++------------------- R/mod_bar.R | 2 +- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/R/mod_DBSelector.R b/R/mod_DBSelector.R index fd47c20..0f9352c 100644 --- a/R/mod_DBSelector.R +++ b/R/mod_DBSelector.R @@ -89,22 +89,6 @@ filtra_datos <- function(datos_filtrados, return(datos_filtrados) } -# Esta sólo se encarga de que exista el objeto cache -fc <- function(cache_selected = "./cache_dir") { - fc_c <- memoise::cache_filesystem(cache_selected) - print(paste("Path for DB cache Storage: ", cache_selected)) - return (fc_c) -} - -# Versión memoizada de filtra_datos -mem_filtra_datos <- memoise::memoise( - filtra_datos, - cache = fc(getOption( - "Cache_DB_dir", - default = "./cache_dir" - ) - ) - ) #' DBSelector Server Function #' @@ -130,10 +114,25 @@ mod_DBSelector_server <- function(input, output, session, filtro_bd <- input$filtro_bd filtro_intervalo <- interval_ba_rea() filtro_lugar <- input$filtro_lugar - datos_filtrados <- mem_filtra_datos(datos_filtrados, filtro_incidente, - filtro_bd, filtro_intervalo, filtro_lugar) + datos_filtrados <- dplyr::filter( + datos_filtrados, + (datos_filtrados$timestamp > lubridate::ymd(filtro_intervalo[1]) + & + datos_filtrados$timestamp < lubridate::ymd(filtro_intervalo[2]) + ) + ) + datos_filtrados <- dplyr::filter(datos_filtrados, + fuente %in% filtro_bd) %>% + dplyr::filter(tipo_incidente %in% filtro_incidente) + ### Filter by location (Alcaldias) + if (filtro_lugar != "Total Ciudad de México") { + datos_filtrados <- dplyr::filter(datos_filtrados, + nom_mun == filtro_lugar) + } return(datos_filtrados) - }) + }) %>% + bindCache(input$filtro_incidente, input$filtro_bd, + interval_ba_rea(), input$filtro_lugar) #datafram_re <- datafram_re %>% shiny::debounce(100) seleccion_lugar <- reactive({ input$filtro_lugar diff --git a/R/mod_bar.R b/R/mod_bar.R index 3a95787..2673c6b 100644 --- a/R/mod_bar.R +++ b/R/mod_bar.R @@ -18,7 +18,7 @@ mod_bar_ui <- function(id) { # TODO: deben venir de los datos min = as.Date("2018-01-01", "%Y-%m-%d"), max = as.Date("2020-09-09", "%Y-%m-%d"), - value = c(as.Date("2020-03-01", "%Y-%m-%d"), + value = c(as.Date("2019-08-01", "%Y-%m-%d"), as.Date("2020-09-09", "%Y-%m-%d")) ) ) From 1c5354defedc3f1ba4eee25eca8aa287b746aef3 Mon Sep 17 00:00:00 2001 From: plablo09 Date: Wed, 19 May 2021 16:25:57 -0500 Subject: [PATCH 10/13] Cache en /tmp (base de datos). --- R/app_server.R | 2 -- app.R | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/R/app_server.R b/R/app_server.R index 7b70254..2d26636 100644 --- a/R/app_server.R +++ b/R/app_server.R @@ -5,8 +5,6 @@ #' @import shiny #' @noRd app_server <- function(input, output, session) { - ########To set new upload file size - #options(shiny.maxRequestSize=510*1024^2) actualizar <- getOption("Actualizar_datos") output$menu <- shinydashboard::renderMenu({ shinydashboard::sidebarMenu(id = "tabs", diff --git a/app.R b/app.R index b78c033..fdd558e 100644 --- a/app.R +++ b/app.R @@ -1,7 +1,8 @@ # Launch the ShinyApp (Do not remove this comment) # To deploy, run: rsconnect::deployApp() # Or use the blue button on top of this file - +#options(shiny.maxRequestSize=510*1024^2) +shinyOptions(cache = cachem::cache_disk(file.path(dirname(tempdir()), "myapp-cache"))) pkgload::load_all(export_all = FALSE,helpers = FALSE,attach_testthat = FALSE) options( "golem.app.prod" = TRUE) visualizadorIncidentesViales::run_app() # add parameters here (if any) From c4d70a6122799f7db9de71475746d260c28015f5 Mon Sep 17 00:00:00 2001 From: plablo09 Date: Wed, 19 May 2021 16:43:03 -0500 Subject: [PATCH 11/13] =?UTF-8?q?Nuevo=20tipo=20de=20cache=20en=20gr=C3=A1?= =?UTF-8?q?ficas.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/mod_graficas.R | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/R/mod_graficas.R b/R/mod_graficas.R index fdc18b1..ac647bf 100644 --- a/R/mod_graficas.R +++ b/R/mod_graficas.R @@ -87,8 +87,7 @@ mod_graficas_ui <- function(id) { #' #'@returns The render plot selected in the UI mes_dia_graf <- function(dataframe_rec_in, input) { - cache_dir_o <- getOption("Cache_dir", default = "./cache_dir") - renderCachedPlot({ + renderPlot({ if (input$tiempo_grafica == "Mensual") { ############## Mensual#################### datos <- dataframe_rec_in() @@ -236,16 +235,9 @@ mes_dia_graf <- function(dataframe_rec_in, input) { } return(p) - }, - cacheKeyExpr = list(input$Datos_grafica, - input$tiempo_grafica, - dataframe_rec_in() - ), - cache = diskCache( - dir = cache_dir_o, - max_size = 20 * 1024^2 - ) - ) + } + ) %>% + bindCache(input$Datos_grafica, input$tiempo_grafica, dataframe_rec_in()) } #' Grafica Horas Function @@ -260,10 +252,7 @@ mes_dia_graf <- function(dataframe_rec_in, input) { #' #'@returns The render plot selected in the UI horas_graf <- function(dataframe_rec_in, input) { - # renderPlot({ - cache_dir_o <- getOption("Cache_dir", default = "./cache_dir") - print(cache_dir_o) - renderCachedPlot({ + renderPlot({ datos <- dataframe_rec_in() if(nrow(datos)==0){ ## Grafica vacia @@ -327,15 +316,9 @@ horas_graf <- function(dataframe_rec_in, input) { panel.border = ggplot2::element_blank() ) return(p) - }, - cacheKeyExpr = list(input$tipo_grafica2, - dataframe_rec_in() - ), - cache = diskCache( - dir = cache_dir_o, - max_size = 20 * 1024^2 - ) - ) + } + ) %>% + bindCache(input$tipo_grafica2, dataframe_rec_in()) } #' graficas Server Function #' From 5b422756e8f02d3e82048c4747784c4b44d39a40 Mon Sep 17 00:00:00 2001 From: plablo09 Date: Wed, 19 May 2021 16:43:46 -0500 Subject: [PATCH 12/13] Nombre de la carpeta de cache. --- app.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.R b/app.R index fdd558e..bf9cc59 100644 --- a/app.R +++ b/app.R @@ -2,7 +2,7 @@ # To deploy, run: rsconnect::deployApp() # Or use the blue button on top of this file #options(shiny.maxRequestSize=510*1024^2) -shinyOptions(cache = cachem::cache_disk(file.path(dirname(tempdir()), "myapp-cache"))) +shinyOptions(cache = cachem::cache_disk(file.path(dirname(tempdir()), "vis-viales-cache"))) pkgload::load_all(export_all = FALSE,helpers = FALSE,attach_testthat = FALSE) options( "golem.app.prod" = TRUE) visualizadorIncidentesViales::run_app() # add parameters here (if any) From 7e2a4f2a75072b8e46c3da450a557d318a3fd7ee Mon Sep 17 00:00:00 2001 From: plablo09 Date: Wed, 19 May 2021 17:14:39 -0500 Subject: [PATCH 13/13] Docker actualizado con nuevo cache. --- Dockerfile | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 16555a1..90dc7c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,19 +29,15 @@ ADD ./ /visualizadorIncidentesViales/ RUN R -e "devtools::install_local('/visualizadorIncidentesViales')" #RUN R -e "devtools::install_github('CentroGeo/visualizadorIncidentesViales', force=TRUE, ref = 'fix_cache_bugs')" -###Make dir for cache -RUN mkdir /cache_dir # expose port EXPOSE 3838 # run app on container start CMD ["R", "-e", \ "options('shiny.port'=3838,shiny.host='0.0.0.0'); \ - options('Actualizar_datos' = TRUE); \ - options('Cache_dir'='/cache_dir');\ - options('Cache_DB_dir'='/cache_dir');\ - library(visualizadorIncidentesViales); \ - visualizadorIncidentesViales::run_app()"] + options('Actualizar_datos' = TRUE); \ + library(visualizadorIncidentesViales); \ + visualizadorIncidentesViales::run_app()"] # CMD ["R", "-e", \ # "devtools::install_github('CentroGeo/visualizadorIncidentesViales', force=TRUE); \ # options('shiny.port'=3838,shiny.host='0.0.0.0'); \