CoolFace
Apppublic

fsotoj/spp_v3

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
App README

Subnational Politics Project (SPP) - Hugging Face Deployment

This repository contains the R Shiny application for the Subnational Politics Project (SPP). It is specifically configured for deployment on Hugging Face Spaces using Docker and serves as the core interactive engine embedded via iframe on subnationalpolitics.com.

๐Ÿš€ Overview

The SPP application provides interactive visualizations (maps, charts, and data tables) for subnational political data across various countries (e.g., Mexico, Argentina, Brazil).

Key Technical Features:

  • โ€”Modular Architecture: Uses Shiny modules for maintainability and scalability.
  • โ€”Dynamic Data Source: Fetches and joins datasets directly from the fsotoj/spp-data repository.
  • โ€”Privacy-First Analytics: Implements a postMessage bridge to handle Google Analytics tracking safely within an iframe context.
  • โ€”Reproducible Environment: Managed via renv and containerized with Docker.

๐Ÿ“‚ Folder Structure

The project follows a modularized R Shiny structure:

  • โ€”Root Files
  • โ€”app.R: Entry point for the Shiny application.
  • โ€”ui.R: defines the frontend layout and UI components.
  • โ€”server.R: Contains the backend logic, reactive expressions, and module coordination.
  • โ€”global.R: Handles data loading, environment setup, and global variable definitions.
  • โ€”analysis/: Contains technical documentation, including:
  • โ€”Repository analysis and architecture overview.
  • โ€”Relational Schema / Entity-Relationship Diagram (ERD).
  • โ€”Google Analytics implementation details.
  • โ€”modules/: Modularized components for specific app sections:
  • โ€”map_module.R: Interactive map visualization.
  • โ€”camera_module_v2.R: Tools for data capture and sharing.
  • โ€”hc_line_module.R: Highcharts-based time-series visualizations.
  • โ€”about_spp_module.R: Project information and credits.
  • โ€”fx/: Helper functions (get_jstree_data.R, update_data.R).
  • โ€”www/: Static web assets (CSS, custom JS for analytics and UI enhancements).
  • โ€”data_cache/: (Generated) Local cache for datasets fetched from GitHub.
  • โ€”public_assets/: (Generated) Local storage for downloaded media/images.
  • โ€”renv.lock: R environment dependency definitions.
  • โ€”Dockerfile: Deployment configuration for Hugging Face (non-root execution).

๐Ÿ›  Tech Stack

  • โ€”Language: R (Shiny)
  • โ€”Charts: Highcharts (highcharter)
  • โ€”Maps: Leaflet
  • โ€”Containerization: Docker (based on rocker/shiny)
  • โ€”Dependency Management: renv
  • โ€”Analytics: Google Analytics (Custom iframe bridge)

๐Ÿ“ก Data Flow

  1. 1.The app starts via app.R / global.R.
  2. 2.It checks for local cached data in data_cache/.
  3. 3.If missing or outdated, it fetches raw Excel/CSV data from the spp-data repository (managed by fsotoj).
  4. 4.Data is processed, joined, and served to the reactive modules.

๐Ÿ“Š Analytics Architecture

Tracking within an iframe is challenging due to browser privacy restrictions. This project solves this by:

  1. 1.Intercepting gtag calls within the Shiny app.
  2. 2.Sending a postMessage to the parent window (subnationalpolitics.com).
  3. 3.The parent site processes the event, ensuring consistent session tracking across the site and the embedded app.