How mrcanofcatfood/sdm-dashboard-fork works
1. Overall shape
- This is a local R/Shiny application for species distribution modelling (SDM), with a second non-interactive pipeline/CLI path for batch execution.
- The repo is organized around a central modelling workflow: ingest occurrence data, build covariates, fit multiple model backends, evaluate, project, and export results.
2. Top-level entry points
- app.R launches the interactive Shiny dashboard.
- launch_app.R is a convenience launcher that starts the app and opens a browser.
- pipeline.R runs the same core workflow headlessly for scripted execution.
- scripts/batch_run.R and related scripts support repeatable batch processing and release automation.
3. Core orchestration layer
- R/core/ contains the control plane: configuration, bootstrap, logging, validation, and the main run_sdm orchestration.
- This layer is the main boundary between UI/pipeline callers and the modelling engine.
- It likely coordinates stage order, handles readiness checks, and routes settings into the modelling and output subsystems.
4. Data ingestion and occurrence handling
- R/data/ handles occurrence records, including general occurrence loading and Darwin Core Archive parsing.
- The app accepts local CSV input, DwCA archives, and GBIF-derived records, with cleaning and validation before modelling.
- The README indicates coordinate cleaning, thinning, and source summaries are part of this layer’s responsibility.
5. Covariate subsystem
- R/covariates/ is responsible for environmental predictor acquisition, caching, stacking, and selection.
- It covers WorldClim climate layers, elevation, soil, NDVI, vegetation, drought, UV, human footprint, land-use/land-cover, future climate projections, and predictor selection/VIF filtering.
- This is the main data-preparation boundary where external raster services and local cached rasters enter the workflow.
6. Modeling engine
- R/models/ is the algorithm registry and training/prediction layer.
- It includes stable backends such as GLM, GAM, MaxNet, Random Forest, XGBoost, ESM variants, multi-ensemble, plus conditional or legacy paths like DNN, JSDM, rangebag, and biomod2 integration.
- Cross-validation, calibration, tuning, permutation importance, prediction, and ensemble logic live here, so this folder is the core computational subsystem.
7. Ecology and post-model analytics
- R/ecology/ contains derived analyses that consume fitted models or suitability surfaces.
- Functions here cover climate matching, EOO/AOO, AOA, niche overlap, species richness stacking, dispersal simulation, CLIMEX import, extrapolation/MESS-style checks, and range-size change.
- These are downstream analytical products, separate from model fitting itself.
8. Shiny UI composition
- R/ui/ defines the dashboard shell: header, main tabs, sidebar controls, and Leaflet-related plugins.
- R/modules/ splits the app into screen-level units such as data acquisition, model execution, readiness checks, and results display.
- The architecture is a modular Shiny app rather than a monolithic server script, which matters for diagramming user interactions and state flow.
9. Output and reporting
- R/output/ converts model and ecology results into user-facing deliverables: metrics, plots, response curves, manifests, reports, ODMAP output, and script export.
- This layer is the final transformation boundary from in-memory analysis objects into files, summaries, and reproducible artifacts.
- The repository also supports batch summaries and structured run logs, which suggests output is designed for both interactive review and offline auditability.
10. Client-side state and presentation
- www/ holds browser assets such as CSS and JavaScript for theming, settings persistence, and map/plugin behavior.
- These assets affect UI state management, but not core modelling logic.
- The app appears to persist some preferences locally in the browser, so user settings are partly client-side and partly server-side.
11. Execution model and background work
- The app supports long-running model runs without blocking the UI, with a cancelable background execution path referenced in the README.
- That implies a separation between interactive Shiny event handling and asynchronous job execution, likely mediated through process isolation rather than a single synchronous request cycle.
- This is important for architecture diagrams because “model run” is not just a UI action; it is a separate execution lane.
12. External dependencies and services
- Key external inputs include GBIF for occurrence acquisition, WorldClim for climate rasters, OpenTopography for elevation, and optional user-provided future climate layers and soil rasters.
- The app depends on a substantial R geospatial/modeling stack, especially packages like terra, shiny, leaflet, mgcv, maxnet, ranger, xgboost, ecospat, blockCV, and optionally torch/cito, Hmsc, and biomod2.
- These dependencies materially shape runtime requirements, especially on desktop, Windows, and Docker.
13. Operational boundaries
- Generated artifacts and sensitive working data are intentionally kept out of version control: outputs, caches, downloaded rasters, logs, and API keys are local-only.
- The repo is meant to be run as a desktop-friendly local analysis environment, not as a hosted multi-user service.
- Docker and Windows launcher support are packaging layers around the same local architecture, not separate application tiers.
Main entry points: run_sdm.R run_sdm · app.R app.R · prediction.R Prediction · mod_model_run.R Modules
Components 22
Entry points
Interactive and headless launch paths
- app.R · Starts the interactive dashboard
app.R - launch_app.R · Convenience wrapper that opens the app
launch_app.R - pipeline.R · Headless execution path for scripted runs
pipeline.R - batch_run.R · Repeatable batch and release-oriented execution
scripts/batch_run.R
Core orchestration
Configuration, validation, bootstrap, and run control
- run_sdm · Main workflow coordinator for SDM runs
R/core/run_sdm.R - bootstrap · Environment and package initialization
R/core/bootstrap.R - config · Runtime configuration and app settings
R/core/config.R - validation · Readiness and input validation
R/core/validation.R
Data prep
Occurrence ingestion and spatial predictors
- Occurrences · Occurrence loading and cleaning
R/data/occurrences.R - DwCA parse · Darwin Core Archive ingestion
R/data/occurrences_dwca.R - Covariates · Predictor acquisition, caching, stacking, and selection
R/covariates/covariates_stack.R - Future proj · Future climate and projection support
R/covariates/future_projection.R
Model engine
Algorithm registry, tuning, validation, and prediction
- Registry · Backend registry and dispatch
R/models/model_registry.R - CV engine · Cross-validation folds and evaluation flow
R/models/cv_engine.R - Calibration · Model fitting, tuning, and calibration
R/models/calibration.R - Prediction · Suitability prediction and projection
R/models/prediction.R
Analysis
Derived ecology and post-model calculations
- Ecology · Climate matching, range metrics, niche overlap, and dispersal
R/ecology/climate_matching.R
Shiny UI
Browser interface and screen modules
Outputs
Reports, metrics, exports, and run artifacts
- Reporting · Metrics, plots, reports, manifests, and script export
R/output/report.R - Batch output · Structured batch summaries and output packaging
R/output/batch_runner.R
Assets
Client-side presentation and settings
- Map plugins · Leaflet and browser-side UI helpers
R/ui/leaflet_plugins.R
Connections 24
- launch_app.R → app.R: starts · Launch helper invokes the Shiny app
- app.R → UI shell: builds · App composes the dashboard UI
- app.R → Modules: serves · App wires server logic through modules
- pipeline.R → run_sdm: executes · Headless pipeline calls the same orchestration path
- batch_run.R → run_sdm: runs · Batch automation triggers model workflow execution
- run_sdm → bootstrap: initializes · Workflow starts with environment/bootstrap setup
- run_sdm → config: reads · Workflow consumes runtime configuration
- run_sdm → validation: checks · Workflow validates inputs and readiness
- run_sdm → Occurrences: loads · Workflow ingests occurrence data
- Occurrences → DwCA parse: parses · DwCA is one supported occurrence source
- run_sdm → Covariates: prepares · Workflow builds the environmental predictor stack
- Covariates → Future proj: projects · Covariate preparation can include future layers
- run_sdm → Registry: selects · Workflow chooses model backends through the registry
- Registry → CV engine: orchestrates · Registry-backed models use shared CV and evaluation flow
- CV engine → Calibration: trains · Cross-validation feeds model calibration and fitting
- Calibration → Prediction: produces · Fitted models generate predictions and projections
- Prediction → Reporting: exports · Predictions feed metrics, plots, reports, and artifacts
- Prediction → Ecology: analyzes · Post-model ecology consumes suitability surfaces and outputs
- Ecology → Reporting: summarizes · Derived analyses are exported to user-facing deliverables
- Modules → validation: gates · UI readiness checks gate model execution
- Modules → run_sdm: triggers · Modules hand off to the shared orchestration layer
- UI shell → Map plugins: uses · UI shell relies on browser/map helpers
- run_sdm → Batch output: packages · Batch runs collect structured outputs and summaries
- Reporting → Batch output: feeds · Reports and artifacts are collected for batch workflows