From 741fb42cb3e25bad4bfe811f24ad43b9a6116055 Mon Sep 17 00:00:00 2001 From: viniciusoike Date: Sat, 26 Sep 2026 00:32:54 -0300 Subject: [PATCH] Use CARTO rastertiles URL and warn when basemap key is missing The deployed app showed watermarked tiles because CARTO_BASEMAP_SHINY was not set on Connect Cloud. Tiles now use the URL format CARTO documents for keyed requests, and startup warns when the key is empty so the problem shows up in the logs. Co-Authored-By: Claude Opus 5.5 (1M context) --- global.R | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/global.R b/global.R index a7b1223..80c1beb 100644 --- a/global.R +++ b/global.R @@ -333,13 +333,21 @@ metro_theme <- bs_theme( # because leaflet.providers 2.0.0 has no {key} slot in the CartoDB template # (rstudio/leaflet#965), so build the tile layer by hand. The key is # restricted by referrer in the CARTO dashboard; without it (or from a domain -# outside the allowlist) tiles come back watermarked or 403. +# outside the allowlist) tiles come back watermarked or 403. On Connect Cloud +# the key must be set as an app environment variable. CARTO_KEY <- Sys.getenv("CARTO_BASEMAP_SHINY") +if (!nzchar(CARTO_KEY)) { + cli::cli_warn(c( + "{.envvar CARTO_BASEMAP_SHINY} is not set.", + "i" = "CARTO basemap tiles will show an API key watermark." + )) +} + add_carto_tiles <- function(map, variant = "light_all") { url <- paste0( - "https://{s}.basemaps.cartocdn.com/", + "https://basemaps.cartocdn.com/rastertiles/", variant, "/{z}/{x}/{y}{r}.png" ) @@ -354,7 +362,7 @@ add_carto_tiles <- function(map, variant = "light_all") { '© OpenStreetMap', 'contributors © CARTO' ), - options = tileOptions(subdomains = "abcd", maxZoom = 20) + options = tileOptions(maxZoom = 20) ) return(map) }