Observable Framework

repository·main·Indexed 25 days ago

https://github.com/observablehq/framework

An open-source static site generator optimized for data-driven applications like dashboards and reports. It bridges front-end interactivity with back-end data analysis using build-time data loaders in JavaScript, TypeScript, Python, or Bash to fetch and process data from sources like Apache Parquet, Airtable, Databricks, and the US Census Bureau.

Tokens
87.9K
Snippets
285
Records
495
Agent score
84%

What's inside @observablehq/framework

  1. Overview of Observable Framework capabilities

    main

    Observable Framework consists of three core components:

    1. Local development server: Provides a preview of your application locally with instant updates as you save changes.
    2. Static site generator: Compiles Markdown, JavaScript, assets, and data snapshots (generated by loaders) into a static site suitable for hosting anywhere.
    3. Command-line interface (CLI): Automates builds and deployments to share your application securely.
  2. Overview of the Mortgage Rates example project

    main
    This project demonstrates how to use Observable Framework to track and visualize mortgage rates published by Freddie Mac. It showcases the use of a TypeScript data loader to fetch and transform external CSV data, and uses Observable Plot to create interactive visualizations within Markdown files.
  3. Overview of Observable Framework

    main

    Observable Framework (or "Framework") is an open-source static-site generator designed specifically for building data apps. Data apps are applications focused on displaying data to help users derive insights or evaluate decisions.

    Common use cases include:

    • Interactive visualizations for self-service analysis.
    • Live dashboards that contextualize current events with historical trends.
    • Point-in-time reports combining graphics and prose for in-depth analysis.

    Framework is designed to be highly customizable via code, allowing for integration into existing professional workflows (editors, source control, CI/CD, unit testing, and self-hosting).

  4. Automatic Reactivity in Framework

    main
    Framework provides language-level support for reactivity similar to Observable notebooks. You can write declarative code in vanilla JavaScript that automatically re-runs whenever its dependencies (variables) change, behaving much like a spreadsheet. This eliminates the need to manually manage complex hooks or signals for standard interactive updates.
  5. Understand FileAttachment routing and build output

    main

    Files referenced via FileAttachment in your src directory are automatically detected during build and copied to the dist/_file folder.

    Key behaviors:

    • Content Hashing: Files are renamed with a content hash (e.g., quakes.e5f2eb94.csv) to enable cache breaking. The framework automatically rewrites your code references to match these hashed names.
    • Static Analysis: Only files explicitly referenced via static string literals in FileAttachment are included in the build. This prevents unused assets from bloating your deployment.
    • Automatic Promotion: Certain HTML elements like audio, img, link, picture, and video automatically promote their src or href assets to file attachments in the _file folder.
  6. Understand the Observable Framework project structure

    main

    An Observable Framework project is organized around a source root (defaulting to src) containing Markdown pages, data loaders, and assets. A typical project structure looks like this:

    .
    ├─ src                    # source root
    │  ├─ .observablehq
    │  │  ├─ cache            # data loader cache
    │  │  └─ deploy.json      # deployment metadata
    │  ├─ components
    │  │  └─ dotmap.js        # shared JavaScript module
    │  ├─ data
    │  │  └─ quakes.csv.ts    # data loader
    │  ├─ index.md            # home page
    │  └─ quakes.md           # page
    ├─ .gitignore
    ├─ README.md
    ├─ observablehq.config.js # app configuration
    ├─ package.json           # node package dependencies
    └─ yarn.lock              # node package lockfile

    Key components:

    • src: The source root where all pages (.md), components (.js), and data (.csv, .json, etc.) reside. You can change the source root name using the root config option.
    • src/index.md: The mandatory home page of your application.
    • observablehq.config.js: The configuration file (supports .js or .ts) used to define app settings like sidebar navigation and the app title.
    • src/.observablehq/cache: An autogenerated directory for data loader snapshots. To force data loaders to re-run, you can delete this directory using rm -rf src/.observablehq/cache.
  7. Project structure for the Hotel Bookings example

    main

    The project follows a standard Observable Framework structure with no external dependencies required beyond the Framework itself. Key directories include:

    • src/components/: Reusable visualization components.
    • src/data/: Local data files (e.g., .csv).
    • src/index.md: The main entry point for the dashboard.
    • observablehq.config.js: Framework configuration.
    .
    ├── README.md
    ├── observablehq.config.js
    ├── package.json
    └── src
        ├── components
        │   ├── bigNumber.js
        │   └── donutChart.js
        ├── data
        │   ├── hotelData.csv
        └── index.md
  8. Understand the types of Observable Framework examples

    main

    The repository provides two distinct categories of examples to help you build data apps:

    1. Technique examples: Smaller, piecemeal examples focused on specific development tasks (e.g., "how to load data from Google Analytics" or "how to make a bump chart"). These are intended for copy-pasting reusable code into your project.
    2. Showcase examples: Larger, complete applications that demonstrate how multiple techniques work together to solve high-level user needs (e.g., "how to analyze website traffic"). These are intended for inspiration and demonstrating the full potential of the Framework.
  9. Static-site Architecture and Performance

    main

    Framework uses a static-site architecture to ensure high performance for data-heavy applications:

    • Precomputed Data: Data is computed at build time, ensuring the client receives highly-optimized, aggregated, or anonymized snapshots.
    • Security: Because data loaders run only during the build process, end-users do not need direct access to underlying data sources, making dashboards more secure.
    • Rapid Prototyping: Data loaders allow you to shortcut warehouse changes by pulling data directly into the build process to validate ideas quickly.