meteogate / global.R
alexdum's picture
Sync current state to Hugging Face
bae968e
# global.R for EuroMeteo Explorer
library(shiny)
library(bslib)
library(bsicons)
library(mapgl)
library(sf)
library(dplyr)
library(readr)
library(DT)
library(httr)
library(plotly)
library(lubridate)
library(shinycssloaders)
library(curl)
library(stringr)
library(purrr)
library(arrow)
library(shinyjs)
library(writexl)
# --- Configuration ---
httr::set_config(httr::config(ssl_verifypeer = FALSE))
# MeteoGate Base URL is handled dynamically in funs/helpers.R
# OpenFreeMap Style URLs
ofm_positron_style <- "https://tiles.openfreemap.org/styles/positron"
ofm_bright_style <- "https://tiles.openfreemap.org/styles/bright"
# EOX Sentinel-2 Cloudless (Free for commercial use with attribution)
# Using 2016 for safest CC-BY 4.0 license or 2023 with mandatory attribution
sentinel_url <- "https://tiles.maps.eox.at/wmts/1.0.0/s2cloudless-2023_3857/default/GoogleMapsCompatible/{z}/{y}/{x}.jpg"
sentinel_attribution <- '<a href="https://s2maps.eu" target="_blank">Sentinel-2 cloudless - by EOX IT Services GmbH</a> (Contains modified Copernicus Sentinel data 2023)'
# --- Source Helper Functions from funs/ folder ---
for (f in list.files("funs", pattern = "\\.R$", full.names = TRUE)) {
source(f)
}
# --- Initialization ---
# Ensure data directory exists
if (!dir.exists("data")) dir.create("data")
# Clear station data cache on startup (fresh cache each app restart)
station_data_cache_dir <- file.path("data", "station_data")
if (dir.exists(station_data_cache_dir)) {
unlink(station_data_cache_dir, recursive = TRUE)
}
dir.create(station_data_cache_dir)
# Clear map observation cache on startup
map_cache_dir <- file.path("data", "map_cache")
if (dir.exists(map_cache_dir)) {
unlink(map_cache_dir, recursive = TRUE)
}
dir.create(map_cache_dir)
# Clear downloaded archive shard cache on startup
parquet_cache_dir <- file.path("data", "parquet_cache")
if (dir.exists(parquet_cache_dir)) {
unlink(parquet_cache_dir, recursive = TRUE)
}
dir.create(parquet_cache_dir)
# Station metadata is loaded reactively in server.R so long-running sessions can refresh.
# Legacy index is no longer needed
mf_index <- NULL
# --- App Defaults ---
# Default to present day for end date, and March 5, 2026 for start date (Archive available data start)
max_year_data <- year(Sys.Date())
default_end_date <- Sys.Date()
default_start_date <- as.Date("2026-03-05")