From bdbdb1a26fd69253ef99c14ef26fcd2a791d97a9 Mon Sep 17 00:00:00 2001 From: eblondel Date: Fri, 31 Jan 2025 16:05:56 +0100 Subject: [PATCH] change paths for dockerized app --- assets/core/data_access_utils.R | 10 ++++++---- global.R | 13 ++++++++----- package.json | 4 ++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/assets/core/data_access_utils.R b/assets/core/data_access_utils.R index b2864d3..24725a5 100644 --- a/assets/core/data_access_utils.R +++ b/assets/core/data_access_utils.R @@ -1016,7 +1016,8 @@ loadLocalDataset <- function(filename){ #loadLocalCountryDatasets #@deprecated loadLocalCountryDatasets <- function(config){ - country_dir <- sprintf("./data/country/%s", config$country_profile$iso3) + local_dir <- if(config$local) "../calipseo-data" else "data" + country_dir <- sprintf("%s/country/%s", local_dir, config$country_profile$iso3) if(dir.exists(country_dir)){ files <- list.files(path = country_dir, full.names = TRUE) for(file in files){ @@ -1028,8 +1029,8 @@ loadLocalCountryDatasets <- function(config){ #getLocalCountryDataset getLocalCountryDataset <- function(config,filename){ - #get(name, envir = CALIPSEO_SHINY_ENV) - country_dir <- sprintf("../calipseo-data/country/%s", config$country_profile$iso3) + local_dir <- if(config$local) "../calipseo-data" else "data" + country_dir <- sprintf("%s/country/%s", local_dir, config$country_profile$iso3) filename <- file.path(country_dir, filename) data <- switch(mime::guess_type(filename), "application/json" = jsonlite::read_json(filename), @@ -1042,7 +1043,8 @@ getLocalCountryDataset <- function(config,filename){ #@deprecated getLocalCountryDatasets <- function(config){ out <- list() - country_dir <- sprintf("../calipseo-data/country/%s", config$country_profile$iso3) + local_dir <- if(config$local) "../calipseo-data" else "data" + country_dir <- sprintf("%s/country/%s", local_dir, config$country_profile$iso3) if(dir.exists(country_dir)){ files <- list.files(path = country_dir, full.names = TRUE) out <- lapply(files, function(file){ diff --git a/global.R b/global.R index 784f6a5..321a108 100644 --- a/global.R +++ b/global.R @@ -60,16 +60,21 @@ require(artfishr) #config #--------------------------------------------------------------------------------------- #default config_file path for DEPLOYMENT -config_file <- "/etc/shiny-server/config.yml" +config_file <- "/etc/calipseo-shiny/config.yml" #local configuration #If you are an R developer, you need to create a .REnviron file (no file extension) in /shiny-calipseo dir #The file should include the local path for your shiny config file in that way: #CALIPSEO_SHINY_CONFIG= +local <- FALSE local_config_file <- Sys.getenv("CALIPSEO_SHINY_CONFIG") -if(nzchar(local_config_file)) config_file <- local_config_file +if(nzchar(local_config_file)){ + config_file <- local_config_file + local <- TRUE +} appConfig <- suppressWarnings(yaml::read_yaml(config_file)) +appConfig$local <- local if(is.null(appConfig$auth)) appConfig$auth <- FALSE @@ -77,7 +82,7 @@ if(is.null(appConfig$auth)) appConfig$auth <- FALSE if(is.null(appConfig$language)) appConfig$language <- "en" #shiny-storage check -default_store_dir <- "/srv/shiny-server/shiny-calipseo-store" +default_store_dir <- "/srv/calipseo-shiny-store" #shiny-storage in dev (assume Windows OS for now) if(Sys.info()[["sysname"]] == "Windows") default_store_dir <- "out" if(is.null(appConfig$store)) appConfig$store <- default_store_dir @@ -106,8 +111,6 @@ CALIPSEO_SHINY_ENV <- new.env() core_assets <- list.files("assets/core", pattern = ".R", full.names = T) for(core_asset in core_assets) source(core_asset) -#addResourcePath(prefix = "calipseo-data", directoryPath = "../calipseo-data") - #country R script utils country_assets <- list.files(path = file.path("./assets/country", appConfig$country_profile$iso3), pattern = ".R", recursive = TRUE, full.names = TRUE) diff --git a/package.json b/package.json index d0b7d33..3a9de25 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "id": "shiny-calipseo", - "version": "2.0.0", - "date": "2025-01-30", + "version": "2.0.0-sp3", + "date": "2025-01-31", "dependencies": [ {"package": "dotenv", "version": "1.0.3", "repos": "https://cran.r-project.org"}, {"package": "htmltools", "version": "0.5.2", "repos": "https://cloud.r-project.org"},