This repository houses a production-ready, stateless map-tiler microservice leveraging TiTiler inside a Shiny for Python ASGI wrapper created with the assistance of LLM.
It is specifically engineered to bypass platform constraints on environments like Posit Connect Cloud, which support standard Python web frameworks (like Shiny) but block raw API frameworks (like FastAPI). By routing incoming data traffic through an ASGI interceptor, this service runs as a high-performance headless tile server under a standard Shiny footprint.
- Posit Connect Cloud Compliant: Disguised as a standard Shiny application to satisfy cloud platform hosting validations.
- Custom ASGI Routing Middleware: Intercepts incoming network requests matching the
/cogprefix and automatically transforms clean, simple short paths (/cog/tiles/{z}/{x}/{y}.png) into standard OGCWebMercatorQuadpaths behind the scenes. - On-the-Fly Tile Generation: Transmutes massive multispectral and floating-point Cloud Optimized GeoTIFF (COG) files into lightweight web-standard tiles (
256x256pixel PNGs) instantaneously via HTTP range requests.
.
├── app.py # Custom ASGI interceptor routing traffic to TiTiler or Shiny
├── test.py # Sample map widget using the API (Local)
└── requirements.txt # Frozen production dependencies for environment builds
Ensure you have Python 3.9+ installed. Create a clean virtual environment and install the required packages:
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
pip install -r requirements.txtuvicorn app:app --host 127.0.0.1 --port 8000 --reloadOpen your browser and test the splitting pathways:
- Shiny UI Fallback: http://127.0.0.1:8000/ (Displays a minimal service confirmation landing page)
- Live Clean Tile Generation: Copy and paste the link below to verify that the intercept middleware correctly maps and colors a tile sample over network streams:
Open a second terminal window, and run the following bash script on a different port (e.g., 8500) so it doesn't conflict with the tiler:
shiny run --port 8500 test.pyBecause this repo structures the application around a primary shiny_app object definition alongside standard requirements, you can deploy it directly via Posit Connect Cloud.
- Push this directory to a repository on GitHub.
- Log into your Posit Connect Cloud account dashboard.
- Click Publish -> From GitHub
- Choose Shiny as your deployment framework and select your repository.
The platform will automatically provision the environment, download your dependencies, and expose a live, permanent public URL.
Once deployed, you can query your custom cloud endpoint cleanly from your main application dashboard (e.g., inside an ipyleaflet rendering function):
import requests
from ipyleaflet import Map, TileLayer
def get_map_widget(cog_http_url):
# Standard URL encoding prevents breaks from specialized remote paths
encoded_cog = requests.utils.quote(cog_http_url, safe="")
# Replace with your actual live Posit Connect Cloud app URL
tiler_base_url = "[https://connect.posit.cloud/user/content/12345](https://connect.posit.cloud/user/content/12345)"
# Target our clean short URL layout handled by the custom middleware
tile_string = f"{tiler_base_url}/cog/tiles/{{z}}/{{x}}/{{y}}.png?url={encoded_cog}&colormap_name=ylgn"
density_layer = TileLayer(url=tile_string, name="Dynamic Distribution Grid")
m = Map(layers=[density_layer], center=[64.2, -149.5], zoom=4)
return mThis repository is open-source and available under the MIT License.