Skip to content

Latest commit

 

History

History
95 lines (68 loc) · 4.79 KB

AGENTS.md

File metadata and controls

95 lines (68 loc) · 4.79 KB

AGENTS.md

How apps in this repo are built. Read this before adding or editing a template.

Each top-level folder is one self-contained Dash app that Plotly Cloud deploys on its own. An app folder must never import from another folder or from the repo root.

App folder layout

<app-folder>/
├── app.py              # Dash app; must expose `server = app.server`
├── why_plotly.py       # Copy of shared_components/why_plotly.py (do not edit here)
├── requirements.txt    # Pinned runtime deps (dash, plotly, gunicorn, ...)
├── requirements-dev.txt# Optional: deps only needed by scripts/ (e.g. rdkit)
├── Procfile            # web: gunicorn app:server --workers 2 --timeout 120 --preload
├── .python-version     # 3.13
├── .gitignore          # __pycache__/, .venv/, .DS_Store
├── plotly-cloud.toml   # name / app_id / app_url, written by Plotly Cloud on first publish
├── README.md           # What the app shows, where the data comes from, screenshot
├── assets/             # style.css, screenshot.png, logo/svg, clientside JS
├── data/               # Pre-built data files the app reads (if any)
└── scripts/            # Optional: build_data.py etc. that generate data/

Other modules (theme.py, figures.py, data.py, domain logic) sit next to app.py when app.py gets long.

Conventions

  • Stack: Dash (currently dash==4.4.1), Plotly, Dash Mantine Components + dash-iconify for UI, dash-ag-grid for tables. Pin exact versions in requirements.txt.
  • Serving: server = app.server in app.py, and a Procfile running gunicorn app:server. Keep if __name__ == "__main__": app.run(debug=True, port=...) for local runs.
  • Data: the deployed app only reads files in data/ (or fetches from a public URL). Heavy dependencies used to generate data go in requirements-dev.txt and scripts/, never in requirements.txt. Synthetic data is fine; say so in the README.
  • Styling: put CSS in assets/style.css. Keep chart colours in Python in sync with the CSS (a theme.py or a constants block at the top of app.py).
  • README: plain description of the question the app answers, what's on screen, how the data was made, what it's built with, and ![Screenshot of app](assets/screenshot.png).
  • Add the app to the list in the root README.md.

GitHub ("View source") and "Why Plotly" buttons

Every app shows two buttons:

  • View source: links to the app's folder on GitHub, https://github.com/plotly/plotly-cloud-templates/tree/main/<app-folder>.
  • Why Plotly: opens a drawer with the Dash Enterprise pitch (security, deployment, licensing, comparison table).

Both come from why_plotly.py. It is self-contained: plain dash.html components, one clientside callback (ids prefixed wp-), and CSS scoped under .wp-* that it injects into the page itself. It works with any component library, layout function or multi-page app.

Option 1: floating buttons (default)

The buttons float bottom-left. Call add_why_plotly once, after app.layout is set:

from why_plotly import add_why_plotly

app.layout = ...
add_why_plotly(app, "<app-folder>")

Option 2: buttons in the app's header

Use this when the app has its own header bar. Render header_buttons in the header, passing the app's own header-link class so they match its other links, and turn off the floating pair:

from why_plotly import add_why_plotly, header_buttons

header = dmc.AppShellHeader(
    dmc.Group([
        ...,
        html.Div(header_buttons("<app-folder>", className="header-btn"), className="header-actions"),
    ])
)
app.layout = ...
add_why_plotly(app, "<app-folder>", floating=False)

Examples: compound-triage, self-driving.

The second argument must be the app's exact folder name, or the GitHub link will 404.

Editing the buttons or the pitch

shared_components/why_plotly.py is the single source of truth. The pitch text (TITLE, QA, COMPARE, ...) is at the top of that file. Never edit an app's copy; edit the shared file, then from the repo root:

python shared_components/sync.py          # copy it into every app folder
python shared_components/sync.py --check  # list stale copies, exit 1 if any

sync.py writes why_plotly.py into every folder that has an app.py and warns if that app.py doesn't call add_why_plotly().

Adding a new app checklist

  1. Create <app-folder>/ with the layout above.
  2. Run python shared_components/sync.py to drop in why_plotly.py.
  3. Call add_why_plotly(app, "<app-folder>") (or the header variant).
  4. Run locally: pip install -r requirements.txt && python app.py.
  5. Add assets/screenshot.png and the README, and list the app in the root README.md.
  6. Publish by uploading the folder at cloud.plotly.com.