@thanhnguyxn/pixelcraft 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/plugins/marketplace.json +20 -0
- package/.antigravity-plugin/plugin.json +32 -0
- package/.claude-plugin/marketplace.json +20 -0
- package/.claude-plugin/plugin.json +22 -0
- package/.codex-plugin/plugin.json +45 -0
- package/.cursor-plugin/marketplace.json +17 -0
- package/.cursor-plugin/plugin.json +27 -0
- package/.devin-plugin/plugin.json +21 -0
- package/.github/plugin/marketplace.json +34 -0
- package/CHANGELOG.md +159 -0
- package/GEMINI.md +1 -0
- package/LICENSE +21 -0
- package/README.md +264 -2
- package/SECURITY.md +28 -0
- package/assets/README.md +28 -0
- package/assets/pixelcraft-logo-128.png +0 -0
- package/assets/pixelcraft-logo-256.png +0 -0
- package/assets/pixelcraft-logo-512.png +0 -0
- package/bin/pixelcraft.mjs +852 -0
- package/docs/ARCHITECTURE.md +105 -0
- package/docs/DESIGN-RATIONALE.md +191 -0
- package/docs/INSTALL.md +221 -0
- package/evals/README.md +37 -0
- package/evals/fixtures/3d-web-engineering.json +69 -0
- package/evals/fixtures/README.md +36 -0
- package/evals/fixtures/acceptance-checklist-rule03-gate.json +43 -0
- package/evals/fixtures/ai-ui-libraries.json +53 -0
- package/evals/fixtures/audio-visual-accessibility.json +69 -0
- package/evals/fixtures/auth-and-checkout-ui.json +53 -0
- package/evals/fixtures/brandkit-identity-governance.json +48 -0
- package/evals/fixtures/build-and-architecture.json +53 -0
- package/evals/fixtures/canvas-and-node-editors.json +53 -0
- package/evals/fixtures/chat-ai-exfiltration-ime-hitl-gate.json +43 -0
- package/evals/fixtures/completion-gate-scan-until-clean.json +44 -0
- package/evals/fixtures/component-systems.json +53 -0
- package/evals/fixtures/component-testing.json +53 -0
- package/evals/fixtures/constrained-voice-and-tv.json +43 -0
- package/evals/fixtures/creative-code-rendering.json +69 -0
- package/evals/fixtures/creative-reference-evidence.json +67 -0
- package/evals/fixtures/data-app-python-marimo.json +49 -0
- package/evals/fixtures/desktop-cpp-juce-audio.json +49 -0
- package/evals/fixtures/desktop-csharp-avalonia.json +49 -0
- package/evals/fixtures/desktop-native-workspace.json +48 -0
- package/evals/fixtures/desktop-python-anti-tkinter.json +49 -0
- package/evals/fixtures/direction-prototype-complexity.json +29 -0
- package/evals/fixtures/document-prepress-pdfx4-tounicode.json +43 -0
- package/evals/fixtures/document-rust-typst-invoice.json +49 -0
- package/evals/fixtures/document-typst-and-print-css.json +43 -0
- package/evals/fixtures/email-mjml-dark-mode.json +49 -0
- package/evals/fixtures/email-outlook-and-plaintext.json +43 -0
- package/evals/fixtures/enterprise-data-ui.json +53 -0
- package/evals/fixtures/extended-tui-toolkits.json +53 -0
- package/evals/fixtures/extensions-mv3-and-vscode.json +43 -0
- package/evals/fixtures/file-upload-media-ui.json +53 -0
- package/evals/fixtures/finish-gate-anti-slop.json +30 -0
- package/evals/fixtures/forms-accessibility-negative.json +29 -0
- package/evals/fixtures/forms-validation.json +53 -0
- package/evals/fixtures/game-go-ebitengine.json +49 -0
- package/evals/fixtures/game-godot-gdscript.json +49 -0
- package/evals/fixtures/game-ui-hud-and-engines.json +43 -0
- package/evals/fixtures/handoff-fidelity-tolerance.json +29 -0
- package/evals/fixtures/i18n-engineering.json +53 -0
- package/evals/fixtures/local-first-sync.json +53 -0
- package/evals/fixtures/lynxjs.json +53 -0
- package/evals/fixtures/maizzle-email.json +53 -0
- package/evals/fixtures/maps-geospatial.json +53 -0
- package/evals/fixtures/media-og-and-video-export.json +43 -0
- package/evals/fixtures/media-players.json +53 -0
- package/evals/fixtures/mobile-compose-16kb-foldable-store-gate.json +44 -0
- package/evals/fixtures/mobile-elixir-liveview-native.json +49 -0
- package/evals/fixtures/mobile-flutter-dynamic-type.json +49 -0
- package/evals/fixtures/mobile-harmonyos-arkui.json +49 -0
- package/evals/fixtures/mobile-jetpack-compose.json +49 -0
- package/evals/fixtures/mobile-swiftui-ios.json +49 -0
- package/evals/fixtures/motion-engineering.json +69 -0
- package/evals/fixtures/pdfjs-and-pptx.json +53 -0
- package/evals/fixtures/plan-brownfield-evidence.json +28 -0
- package/evals/fixtures/plan-discovery-interview.json +31 -0
- package/evals/fixtures/plan-grill-me-brainstorm-gate.json +49 -0
- package/evals/fixtures/reactive-data-apps.json +53 -0
- package/evals/fixtures/review-evidence-audit.json +43 -0
- package/evals/fixtures/rich-text-and-code-editors.json +53 -0
- package/evals/fixtures/scrollytelling-resilience.json +70 -0
- package/evals/fixtures/spatial-xr-comfort-and-platforms.json +43 -0
- package/evals/fixtures/state-architecture.json +53 -0
- package/evals/fixtures/styling-ecosystem.json +53 -0
- package/evals/fixtures/token-tooling.json +53 -0
- package/evals/fixtures/tui-go-bubbletea.json +49 -0
- package/evals/fixtures/tui-rust-ratatui-grapheme-paste-teardown.json +44 -0
- package/evals/fixtures/tui-rust-ratatui.json +49 -0
- package/evals/fixtures/ux-state-matrix-and-i18n.json +43 -0
- package/evals/fixtures/visual-qa-task-evidence.json +29 -0
- package/evals/fixtures/web-3d-engines.json +53 -0
- package/evals/fixtures/web-php-laravel-filament.json +49 -0
- package/evals/fixtures/web-ruby-viewcomponent-phlex.json +49 -0
- package/evals/fixtures/workflow-checkpoints.json +30 -0
- package/evals/pixelcraft-accessibility.md +74 -0
- package/evals/pixelcraft-brandkit.md +58 -0
- package/evals/pixelcraft-chat-ui.md +55 -0
- package/evals/pixelcraft-constrained.md +55 -0
- package/evals/pixelcraft-craft.md +76 -0
- package/evals/pixelcraft-data-apps.md +55 -0
- package/evals/pixelcraft-dataviz.md +59 -0
- package/evals/pixelcraft-desktop.md +55 -0
- package/evals/pixelcraft-direction.md +77 -0
- package/evals/pixelcraft-document.md +55 -0
- package/evals/pixelcraft-email.md +55 -0
- package/evals/pixelcraft-extensions.md +55 -0
- package/evals/pixelcraft-game-ui.md +59 -0
- package/evals/pixelcraft-handoff.md +57 -0
- package/evals/pixelcraft-media.md +55 -0
- package/evals/pixelcraft-mobile.md +59 -0
- package/evals/pixelcraft-patterns.md +73 -0
- package/evals/pixelcraft-plan.md +127 -0
- package/evals/pixelcraft-review.md +63 -0
- package/evals/pixelcraft-spatial.md +55 -0
- package/evals/pixelcraft-tokens.md +57 -0
- package/evals/pixelcraft-tui.md +55 -0
- package/evals/pixelcraft-ux.md +59 -0
- package/evals/pixelcraft-visual-qa.md +86 -0
- package/evals/pixelcraft-web.md +89 -0
- package/evals/pixelcraft.md +70 -0
- package/gemini-extension.json +6 -0
- package/install.ps1 +341 -0
- package/install.sh +512 -0
- package/package.json +91 -4
- package/plugin.json +29 -0
- package/scripts/build-adapters.mjs +288 -0
- package/scripts/build-release-archives.mjs +61 -0
- package/scripts/build-skill-zips.mjs +94 -0
- package/scripts/run-evals.mjs +397 -0
- package/scripts/sync-docs.mjs +381 -0
- package/scripts/test-build-adapters.mjs +61 -0
- package/scripts/test-cross-platform-qa.mjs +359 -0
- package/scripts/test-distribution.mjs +203 -0
- package/scripts/test-export-tokens.mjs +361 -0
- package/scripts/test-finish-gate.mjs +271 -0
- package/scripts/test-installers.mjs +216 -0
- package/scripts/test-release-archives.mjs +42 -0
- package/scripts/test-shoot.mjs +87 -0
- package/scripts/test-slop-scan.mjs +416 -0
- package/scripts/test-style-inventory.mjs +234 -0
- package/scripts/test-sync-docs.mjs +140 -0
- package/scripts/test-validate-skills.mjs +195 -0
- package/scripts/validate-skills.mjs +658 -0
- package/skills/pixelcraft/SKILL.md +155 -0
- package/skills/pixelcraft/references/design-brief.md +75 -0
- package/skills/pixelcraft/references/floor.md +90 -0
- package/skills/pixelcraft/references/report-template.md +49 -0
- package/skills/pixelcraft/references/stack-detection.md +226 -0
- package/skills/pixelcraft/references/surface-acceptance.md +52 -0
- package/skills/pixelcraft/references/workflow-checkpoints.md +71 -0
- package/skills/pixelcraft-accessibility/SKILL.md +54 -0
- package/skills/pixelcraft-accessibility/references/apg-patterns.md +64 -0
- package/skills/pixelcraft-accessibility/references/motion-canvas.md +57 -0
- package/skills/pixelcraft-accessibility/references/platforms.md +86 -0
- package/skills/pixelcraft-accessibility/references/verification.md +64 -0
- package/skills/pixelcraft-accessibility/references/wcag22-checks.md +99 -0
- package/skills/pixelcraft-brandkit/SKILL.md +127 -0
- package/skills/pixelcraft-brandkit/references/asset-pipeline.md +165 -0
- package/skills/pixelcraft-brandkit/references/brand-governance.md +82 -0
- package/skills/pixelcraft-brandkit/references/layouts.md +88 -0
- package/skills/pixelcraft-brandkit/references/logo-concepting.md +83 -0
- package/skills/pixelcraft-brandkit/references/logo-methods.md +97 -0
- package/skills/pixelcraft-brandkit/references/pixel-art-logos.md +82 -0
- package/skills/pixelcraft-brandkit/references/prompt-template.md +87 -0
- package/skills/pixelcraft-brandkit/references/qa-checklist.md +93 -0
- package/skills/pixelcraft-brandkit/references/visual-modes.md +123 -0
- package/skills/pixelcraft-chat-ui/SKILL.md +57 -0
- package/skills/pixelcraft-chat-ui/references/agentic-workspace.md +66 -0
- package/skills/pixelcraft-chat-ui/references/ai-ui-libraries.md +259 -0
- package/skills/pixelcraft-chat-ui/references/conversation-design.md +84 -0
- package/skills/pixelcraft-chat-ui/references/mobile-business-platforms.md +77 -0
- package/skills/pixelcraft-chat-ui/references/slack-discord.md +80 -0
- package/skills/pixelcraft-constrained/SKILL.md +52 -0
- package/skills/pixelcraft-constrained/references/specialized-hardware.md +90 -0
- package/skills/pixelcraft-constrained/references/tv-wearables.md +134 -0
- package/skills/pixelcraft-constrained/references/voice-ui.md +104 -0
- package/skills/pixelcraft-craft/SKILL.md +58 -0
- package/skills/pixelcraft-craft/references/color.md +125 -0
- package/skills/pixelcraft-craft/references/imagery-icons.md +37 -0
- package/skills/pixelcraft-craft/references/layout-quality.md +65 -0
- package/skills/pixelcraft-craft/references/layout.md +73 -0
- package/skills/pixelcraft-craft/references/motion.md +163 -0
- package/skills/pixelcraft-craft/references/typography.md +110 -0
- package/skills/pixelcraft-data-apps/SKILL.md +86 -0
- package/skills/pixelcraft-data-apps/references/ai-and-internal-data-apps.md +147 -0
- package/skills/pixelcraft-data-apps/references/dash.md +109 -0
- package/skills/pixelcraft-data-apps/references/evidence.md +90 -0
- package/skills/pixelcraft-data-apps/references/gradio.md +103 -0
- package/skills/pixelcraft-data-apps/references/julia-genie.md +89 -0
- package/skills/pixelcraft-data-apps/references/jupyter-widgets.md +91 -0
- package/skills/pixelcraft-data-apps/references/nicegui.md +102 -0
- package/skills/pixelcraft-data-apps/references/observable-framework.md +105 -0
- package/skills/pixelcraft-data-apps/references/panel.md +99 -0
- package/skills/pixelcraft-data-apps/references/r-shiny.md +124 -0
- package/skills/pixelcraft-data-apps/references/reactive-data-apps.md +186 -0
- package/skills/pixelcraft-data-apps/references/reflex.md +116 -0
- package/skills/pixelcraft-data-apps/references/shiny.md +110 -0
- package/skills/pixelcraft-data-apps/references/streamlit.md +113 -0
- package/skills/pixelcraft-dataviz/SKILL.md +60 -0
- package/skills/pixelcraft-dataviz/references/chart-choice.md +55 -0
- package/skills/pixelcraft-dataviz/references/color-accessibility.md +112 -0
- package/skills/pixelcraft-dataviz/references/encoding-tables-dashboards.md +107 -0
- package/skills/pixelcraft-dataviz/references/libraries.md +176 -0
- package/skills/pixelcraft-dataviz/references/maps-geospatial.md +159 -0
- package/skills/pixelcraft-dataviz/references/realtime-graphs-maps-scale.md +92 -0
- package/skills/pixelcraft-desktop/SKILL.md +93 -0
- package/skills/pixelcraft-desktop/references/appkit.md +92 -0
- package/skills/pixelcraft-desktop/references/avalonia.md +95 -0
- package/skills/pixelcraft-desktop/references/cpp-gui.md +129 -0
- package/skills/pixelcraft-desktop/references/electron.md +96 -0
- package/skills/pixelcraft-desktop/references/go-gui.md +83 -0
- package/skills/pixelcraft-desktop/references/gtk.md +97 -0
- package/skills/pixelcraft-desktop/references/javafx-swing.md +81 -0
- package/skills/pixelcraft-desktop/references/qt-pyside-qml.md +88 -0
- package/skills/pixelcraft-desktop/references/rust-gui.md +83 -0
- package/skills/pixelcraft-desktop/references/tauri.md +110 -0
- package/skills/pixelcraft-desktop/references/uno-platform.md +71 -0
- package/skills/pixelcraft-desktop/references/winui-wpf.md +98 -0
- package/skills/pixelcraft-desktop/references/working-context.md +84 -0
- package/skills/pixelcraft-direction/SKILL.md +120 -0
- package/skills/pixelcraft-direction/references/composition-library.md +84 -0
- package/skills/pixelcraft-direction/references/creative-brainstorming.md +72 -0
- package/skills/pixelcraft-direction/references/direction-card.md +64 -0
- package/skills/pixelcraft-direction/references/direction-scoring.md +76 -0
- package/skills/pixelcraft-direction/references/motion-identity.md +67 -0
- package/skills/pixelcraft-direction/references/movements.md +71 -0
- package/skills/pixelcraft-direction/references/reference-analysis.md +37 -0
- package/skills/pixelcraft-direction/references/repetition-history.md +75 -0
- package/skills/pixelcraft-direction/references/slop-fingerprints.md +83 -0
- package/skills/pixelcraft-direction/references/wildcards.md +47 -0
- package/skills/pixelcraft-document/SKILL.md +58 -0
- package/skills/pixelcraft-document/references/archetypes.md +106 -0
- package/skills/pixelcraft-document/references/pdf-tools.md +314 -0
- package/skills/pixelcraft-document/references/pdfjs-and-pptx.md +114 -0
- package/skills/pixelcraft-document/references/print-css.md +187 -0
- package/skills/pixelcraft-document/references/slides.md +198 -0
- package/skills/pixelcraft-email/SKILL.md +80 -0
- package/skills/pixelcraft-email/references/client-quirks.md +113 -0
- package/skills/pixelcraft-email/references/html-tables.md +114 -0
- package/skills/pixelcraft-email/references/maizzle.md +54 -0
- package/skills/pixelcraft-email/references/mjml.md +54 -0
- package/skills/pixelcraft-email/references/react-email.md +95 -0
- package/skills/pixelcraft-extensions/SKILL.md +56 -0
- package/skills/pixelcraft-extensions/references/browser-extensions.md +105 -0
- package/skills/pixelcraft-extensions/references/figma-office.md +106 -0
- package/skills/pixelcraft-extensions/references/ide-and-saas-plugins.md +125 -0
- package/skills/pixelcraft-extensions/references/raycast.md +98 -0
- package/skills/pixelcraft-extensions/references/vscode-webviews.md +100 -0
- package/skills/pixelcraft-game-ui/SKILL.md +80 -0
- package/skills/pixelcraft-game-ui/references/bevy.md +90 -0
- package/skills/pixelcraft-game-ui/references/godot.md +130 -0
- package/skills/pixelcraft-game-ui/references/hud-principles.md +67 -0
- package/skills/pixelcraft-game-ui/references/love2d.md +77 -0
- package/skills/pixelcraft-game-ui/references/monogame.md +68 -0
- package/skills/pixelcraft-game-ui/references/unity-ugui.md +109 -0
- package/skills/pixelcraft-game-ui/references/unity-ui-toolkit.md +107 -0
- package/skills/pixelcraft-game-ui/references/unreal-umg.md +80 -0
- package/skills/pixelcraft-game-ui/references/web-and-middleware-game-ui.md +122 -0
- package/skills/pixelcraft-handoff/SKILL.md +50 -0
- package/skills/pixelcraft-handoff/references/design-translation.md +134 -0
- package/skills/pixelcraft-handoff/references/fidelity-tolerance.md +78 -0
- package/skills/pixelcraft-handoff/references/motion-handoff.md +54 -0
- package/skills/pixelcraft-media/SKILL.md +49 -0
- package/skills/pixelcraft-media/references/banners-video.md +130 -0
- package/skills/pixelcraft-media/references/og-generation.md +154 -0
- package/skills/pixelcraft-media/references/social-cards.md +71 -0
- package/skills/pixelcraft-mobile/SKILL.md +86 -0
- package/skills/pixelcraft-mobile/references/dotnet-maui.md +91 -0
- package/skills/pixelcraft-mobile/references/flet.md +80 -0
- package/skills/pixelcraft-mobile/references/flutter.md +113 -0
- package/skills/pixelcraft-mobile/references/harmonyos-and-emerging-mobile.md +121 -0
- package/skills/pixelcraft-mobile/references/ionic-capacitor.md +87 -0
- package/skills/pixelcraft-mobile/references/jetpack-compose.md +129 -0
- package/skills/pixelcraft-mobile/references/kivy.md +82 -0
- package/skills/pixelcraft-mobile/references/kotlin-multiplatform.md +86 -0
- package/skills/pixelcraft-mobile/references/lynxjs.md +110 -0
- package/skills/pixelcraft-mobile/references/nativescript-and-skip.md +91 -0
- package/skills/pixelcraft-mobile/references/react-native-expo.md +106 -0
- package/skills/pixelcraft-mobile/references/swiftui.md +200 -0
- package/skills/pixelcraft-mobile/references/tactile-interactions.md +55 -0
- package/skills/pixelcraft-mobile/references/task-state-composition.md +85 -0
- package/skills/pixelcraft-mobile/references/uikit.md +92 -0
- package/skills/pixelcraft-patterns/SKILL.md +75 -0
- package/skills/pixelcraft-patterns/references/accessibility-resilience.md +29 -0
- package/skills/pixelcraft-patterns/references/ai-and-offline-patterns.md +54 -0
- package/skills/pixelcraft-patterns/references/auth-onboarding.md +44 -0
- package/skills/pixelcraft-patterns/references/billing-paywalls.md +40 -0
- package/skills/pixelcraft-patterns/references/command-workspace.md +56 -0
- package/skills/pixelcraft-patterns/references/commerce.md +47 -0
- package/skills/pixelcraft-patterns/references/communication.md +45 -0
- package/skills/pixelcraft-patterns/references/creative-tools.md +42 -0
- package/skills/pixelcraft-patterns/references/creative-web-composition.md +38 -0
- package/skills/pixelcraft-patterns/references/dashboard-admin.md +35 -0
- package/skills/pixelcraft-patterns/references/history-diff-undo.md +50 -0
- package/skills/pixelcraft-patterns/references/marketing.md +44 -0
- package/skills/pixelcraft-patterns/references/multi-tenant-rbac.md +47 -0
- package/skills/pixelcraft-patterns/references/narrative-systems.md +42 -0
- package/skills/pixelcraft-patterns/references/notifications-activity.md +57 -0
- package/skills/pixelcraft-patterns/references/pattern-selection.md +80 -0
- package/skills/pixelcraft-patterns/references/scheduling-kanban.md +47 -0
- package/skills/pixelcraft-patterns/references/scroll-implementation.md +37 -0
- package/skills/pixelcraft-patterns/references/search-filtering.md +42 -0
- package/skills/pixelcraft-patterns/references/settings.md +51 -0
- package/skills/pixelcraft-patterns/references/tables-crud.md +43 -0
- package/skills/pixelcraft-plan/SKILL.md +103 -0
- package/skills/pixelcraft-plan/references/design-input.md +69 -0
- package/skills/pixelcraft-plan/references/discovery-interview.md +110 -0
- package/skills/pixelcraft-plan/references/grill-me-protocol.md +63 -0
- package/skills/pixelcraft-plan/references/plan-template.md +134 -0
- package/skills/pixelcraft-plan/references/repo-discovery.md +49 -0
- package/skills/pixelcraft-plan/references/stack-freshness.md +67 -0
- package/skills/pixelcraft-plan/references/stack-selection.md +98 -0
- package/skills/pixelcraft-review/SKILL.md +86 -0
- package/skills/pixelcraft-review/references/audit-report.md +69 -0
- package/skills/pixelcraft-review/references/critique-protocol.md +89 -0
- package/skills/pixelcraft-review/references/heuristics.md +63 -0
- package/skills/pixelcraft-review/references/personas.md +53 -0
- package/skills/pixelcraft-review/references/polish.md +78 -0
- package/skills/pixelcraft-review/scripts/check-acceptance.mjs +619 -0
- package/skills/pixelcraft-review/scripts/fixtures/brand-critique-waivers.json +14 -0
- package/skills/pixelcraft-review/scripts/fixtures/brand-critique.css +18 -0
- package/skills/pixelcraft-review/scripts/fixtures/clean.html +43 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-after-block.css +4 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-at-rules.css +17 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-comments.css +10 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-html-quote-leak.html +12 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-invalid-replacements.css +27 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-longhand-removal.css +34 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-nested-rules.css +19 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-not-visible-skip.css +8 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-outline-shorthands.css +11 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-unknown-and-border.css +15 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-unknown-last-wins.css +19 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-valid-replacements-extended.css +29 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-visible-no-replacement.css +3 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-visible-valid-replacements.css +9 -0
- package/skills/pixelcraft-review/scripts/fixtures/slop.html +28 -0
- package/skills/pixelcraft-review/scripts/slop-scan.mjs +1233 -0
- package/skills/pixelcraft-spatial/SKILL.md +51 -0
- package/skills/pixelcraft-spatial/references/comfort-accessibility.md +39 -0
- package/skills/pixelcraft-spatial/references/platforms.md +147 -0
- package/skills/pixelcraft-tokens/SKILL.md +60 -0
- package/skills/pixelcraft-tokens/assets/tokens.example.json +71 -0
- package/skills/pixelcraft-tokens/assets/tokens.modes.example.json +47 -0
- package/skills/pixelcraft-tokens/references/adoption.md +55 -0
- package/skills/pixelcraft-tokens/references/format.md +84 -0
- package/skills/pixelcraft-tokens/references/governance.md +80 -0
- package/skills/pixelcraft-tokens/references/state-tokens.md +62 -0
- package/skills/pixelcraft-tokens/references/theme-presets.md +122 -0
- package/skills/pixelcraft-tokens/references/token-tooling.md +119 -0
- package/skills/pixelcraft-tokens/scripts/export-tokens.mjs +847 -0
- package/skills/pixelcraft-tui/SKILL.md +76 -0
- package/skills/pixelcraft-tui/references/bubbletea-lipgloss.md +79 -0
- package/skills/pixelcraft-tui/references/extended-tui-toolkits.md +127 -0
- package/skills/pixelcraft-tui/references/ink.md +109 -0
- package/skills/pixelcraft-tui/references/ratatui.md +102 -0
- package/skills/pixelcraft-tui/references/rich.md +82 -0
- package/skills/pixelcraft-tui/references/terminal-protocols.md +80 -0
- package/skills/pixelcraft-tui/references/textual.md +108 -0
- package/skills/pixelcraft-ux/SKILL.md +56 -0
- package/skills/pixelcraft-ux/references/cognitive-walkthrough.md +70 -0
- package/skills/pixelcraft-ux/references/feedback-performance.md +50 -0
- package/skills/pixelcraft-ux/references/flows-ia.md +44 -0
- package/skills/pixelcraft-ux/references/forms.md +151 -0
- package/skills/pixelcraft-ux/references/i18n.md +221 -0
- package/skills/pixelcraft-ux/references/laws.md +39 -0
- package/skills/pixelcraft-ux/references/locale-test-matrix.md +60 -0
- package/skills/pixelcraft-ux/references/state-matrix.md +53 -0
- package/skills/pixelcraft-ux/references/usability-testing.md +84 -0
- package/skills/pixelcraft-ux/references/ux-writing.md +44 -0
- package/skills/pixelcraft-visual-qa/SKILL.md +96 -0
- package/skills/pixelcraft-visual-qa/references/baseline-governance.md +70 -0
- package/skills/pixelcraft-visual-qa/references/capture-desktop-game.md +59 -0
- package/skills/pixelcraft-visual-qa/references/capture-document.md +70 -0
- package/skills/pixelcraft-visual-qa/references/capture-email.md +38 -0
- package/skills/pixelcraft-visual-qa/references/capture-mobile.md +50 -0
- package/skills/pixelcraft-visual-qa/references/capture-terminal.md +35 -0
- package/skills/pixelcraft-visual-qa/references/critique-rubric.md +71 -0
- package/skills/pixelcraft-visual-qa/references/finish-gate.md +35 -0
- package/skills/pixelcraft-visual-qa/references/measured-craft.md +30 -0
- package/skills/pixelcraft-visual-qa/references/motion-capture.md +63 -0
- package/skills/pixelcraft-visual-qa/references/performance-budgets.md +78 -0
- package/skills/pixelcraft-visual-qa/references/realtime-graphics.md +55 -0
- package/skills/pixelcraft-visual-qa/references/task-verification.md +81 -0
- package/skills/pixelcraft-visual-qa/scripts/check-contrast.mjs +442 -0
- package/skills/pixelcraft-visual-qa/scripts/check-email.mjs +397 -0
- package/skills/pixelcraft-visual-qa/scripts/check-pdf.mjs +189 -0
- package/skills/pixelcraft-visual-qa/scripts/check-tui.mjs +321 -0
- package/skills/pixelcraft-visual-qa/scripts/finish-gate.mjs +174 -0
- package/skills/pixelcraft-visual-qa/scripts/fixtures/shoot-aria-modal.html +19 -0
- package/skills/pixelcraft-visual-qa/scripts/fixtures/shoot-audit.html +34 -0
- package/skills/pixelcraft-visual-qa/scripts/fixtures/shoot-modal.html +17 -0
- package/skills/pixelcraft-visual-qa/scripts/fixtures/style-inventory-deferred.js +1 -0
- package/skills/pixelcraft-visual-qa/scripts/fixtures/style-inventory-edge.html +52 -0
- package/skills/pixelcraft-visual-qa/scripts/fixtures/style-inventory.html +80 -0
- package/skills/pixelcraft-visual-qa/scripts/fixtures/style-inventory.js +8 -0
- package/skills/pixelcraft-visual-qa/scripts/shoot.mjs +668 -0
- package/skills/pixelcraft-visual-qa/scripts/style-inventory.mjs +1226 -0
- package/skills/pixelcraft-web/SKILL.md +132 -0
- package/skills/pixelcraft-web/references/accessibility-performance.md +42 -0
- package/skills/pixelcraft-web/references/adaptive-layout.md +69 -0
- package/skills/pixelcraft-web/references/angular.md +108 -0
- package/skills/pixelcraft-web/references/assets-pipeline.md +67 -0
- package/skills/pixelcraft-web/references/astro.md +113 -0
- package/skills/pixelcraft-web/references/audio-reactive.md +61 -0
- package/skills/pixelcraft-web/references/auth-and-checkout-ui.md +115 -0
- package/skills/pixelcraft-web/references/build-and-architecture.md +215 -0
- package/skills/pixelcraft-web/references/canvas-and-node-editors.md +157 -0
- package/skills/pixelcraft-web/references/clojurescript.md +88 -0
- package/skills/pixelcraft-web/references/component-systems.md +102 -0
- package/skills/pixelcraft-web/references/component-testing.md +170 -0
- package/skills/pixelcraft-web/references/creative-effects.md +59 -0
- package/skills/pixelcraft-web/references/creative-runtime.md +34 -0
- package/skills/pixelcraft-web/references/elm.md +53 -0
- package/skills/pixelcraft-web/references/enterprise-data-ui.md +138 -0
- package/skills/pixelcraft-web/references/file-upload-media-ui.md +82 -0
- package/skills/pixelcraft-web/references/forms-validation.md +123 -0
- package/skills/pixelcraft-web/references/fsharp-fable.md +54 -0
- package/skills/pixelcraft-web/references/gsap.md +102 -0
- package/skills/pixelcraft-web/references/html-css.md +220 -0
- package/skills/pixelcraft-web/references/htmx-alpine.md +103 -0
- package/skills/pixelcraft-web/references/i18n-engineering.md +106 -0
- package/skills/pixelcraft-web/references/interaction-and-search-primitives.md +196 -0
- package/skills/pixelcraft-web/references/java-web.md +61 -0
- package/skills/pixelcraft-web/references/kotlin-web.md +57 -0
- package/skills/pixelcraft-web/references/leptos-yew.md +97 -0
- package/skills/pixelcraft-web/references/lit-web-components.md +63 -0
- package/skills/pixelcraft-web/references/local-first-sync.md +105 -0
- package/skills/pixelcraft-web/references/media-players.md +104 -0
- package/skills/pixelcraft-web/references/motion-react.md +96 -0
- package/skills/pixelcraft-web/references/motion-recipes.md +82 -0
- package/skills/pixelcraft-web/references/preact-fresh-hono.md +111 -0
- package/skills/pixelcraft-web/references/pwa.md +230 -0
- package/skills/pixelcraft-web/references/qwik.md +94 -0
- package/skills/pixelcraft-web/references/r3f-integration.md +69 -0
- package/skills/pixelcraft-web/references/react-next.md +168 -0
- package/skills/pixelcraft-web/references/rendering-choice.md +63 -0
- package/skills/pixelcraft-web/references/rendering-performance.md +80 -0
- package/skills/pixelcraft-web/references/rich-text-and-code-editors.md +220 -0
- package/skills/pixelcraft-web/references/rive-lottie.md +73 -0
- package/skills/pixelcraft-web/references/scala-laminar.md +53 -0
- package/skills/pixelcraft-web/references/scene-architecture.md +132 -0
- package/skills/pixelcraft-web/references/server-rendered.md +114 -0
- package/skills/pixelcraft-web/references/shader-workflow.md +77 -0
- package/skills/pixelcraft-web/references/smooth-scroll.md +58 -0
- package/skills/pixelcraft-web/references/solid.md +111 -0
- package/skills/pixelcraft-web/references/state-architecture.md +107 -0
- package/skills/pixelcraft-web/references/styling-ecosystem.md +273 -0
- package/skills/pixelcraft-web/references/svelte.md +111 -0
- package/skills/pixelcraft-web/references/tailwind.md +99 -0
- package/skills/pixelcraft-web/references/video-media.md +69 -0
- package/skills/pixelcraft-web/references/vue-nuxt.md +86 -0
- package/skills/pixelcraft-web/references/web-3d-engines.md +97 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# R Shiny
|
|
2
|
+
|
|
3
|
+
Shiny for R belongs in the rapid data-app space with its own reactive idioms; do not force Python patterns onto R code.
|
|
4
|
+
|
|
5
|
+
## Token mapping and bslib layout
|
|
6
|
+
|
|
7
|
+
Use `bslib::bs_theme(version = 5, ...)` paired with `thematic::thematic_shiny()` so ggplot2/lattice/base plots automatically inherit UI colors and fonts. Build responsive shells with `page_sidebar()`, `page_navbar()`, `layout_columns()`, `card(full_screen = TRUE)`, `value_box()`, and `input_dark_mode()`.
|
|
8
|
+
|
|
9
|
+
## Modern R Shiny idioms (`bslib`, `ExtendedTask` + `mirai`, `bindCache`, `shinychat`/`ellmer`, modules)
|
|
10
|
+
|
|
11
|
+
```r
|
|
12
|
+
library(shiny)
|
|
13
|
+
library(bslib)
|
|
14
|
+
library(mirai)
|
|
15
|
+
library(shinychat)
|
|
16
|
+
library(ellmer)
|
|
17
|
+
|
|
18
|
+
# Start background worker daemons once per R process for non-blocking tasks
|
|
19
|
+
daemons(2)
|
|
20
|
+
onStop(function() daemons(0))
|
|
21
|
+
|
|
22
|
+
# Reusable namespaced module isolating per-instance state
|
|
23
|
+
kpi_module_ui <- function(id) {
|
|
24
|
+
ns <- NS(id)
|
|
25
|
+
card(
|
|
26
|
+
full_screen = TRUE,
|
|
27
|
+
card_header("Regional summary"),
|
|
28
|
+
uiOutput(ns("summary_box"))
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
kpi_module_server <- function(id, region_reactive) {
|
|
33
|
+
moduleServer(id, function(input, output, session) {
|
|
34
|
+
cached_summary <- reactive({
|
|
35
|
+
req(region_reactive())
|
|
36
|
+
query_region_summary(region_reactive())
|
|
37
|
+
}) |> bindCache(region_reactive(), cache = "session") # use "session" for user-private data
|
|
38
|
+
|
|
39
|
+
output$summary_box <- renderUI({
|
|
40
|
+
df <- cached_summary()
|
|
41
|
+
validate(need(nrow(df) > 0, "No records match the selected region."))
|
|
42
|
+
value_box(title = "Total revenue", value = scales::dollar(sum(df$revenue)))
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
ui <- page_sidebar(
|
|
48
|
+
title = "Operations Console",
|
|
49
|
+
theme = bs_theme(version = 5, primary = "#005f73", bg = "#faf8f1", fg = "#161b24"),
|
|
50
|
+
sidebar = sidebar(
|
|
51
|
+
selectInput("region", "Region", choices = c("EMEA", "AMER", "APAC")),
|
|
52
|
+
input_task_button("run_sim", "Run Monte Carlo"),
|
|
53
|
+
input_dark_mode(id = "mode")
|
|
54
|
+
),
|
|
55
|
+
layout_columns(
|
|
56
|
+
kpi_module_ui("kpi"),
|
|
57
|
+
card(card_header("Simulation"), tableOutput("sim_tbl")),
|
|
58
|
+
card(card_header("Analyst chat"), chat_ui("assistant"))
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
server <- function(input, output, session) {
|
|
63
|
+
kpi_module_server("kpi", reactive(input$region))
|
|
64
|
+
|
|
65
|
+
# Non-blocking background computation across sessions via ExtendedTask + mirai
|
|
66
|
+
sim_task <- ExtendedTask$new(function(region) {
|
|
67
|
+
mirai({ run_heavy_simulation(r) }, r = region)
|
|
68
|
+
}) |> bind_task_button("run_sim")
|
|
69
|
+
|
|
70
|
+
observeEvent(input$run_sim, {
|
|
71
|
+
sim_task$invoke(input$region)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
output$sim_tbl <- renderTable({
|
|
75
|
+
res <- sim_task$result()
|
|
76
|
+
validate(need(nrow(res) > 0, "Simulation returned no rows."))
|
|
77
|
+
res
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
# Streaming LLM assistant with shinychat + ellmer
|
|
81
|
+
llm <- chat_openai(system_prompt = "Answer concise analytics questions.")
|
|
82
|
+
observeEvent(input$assistant_user_input, {
|
|
83
|
+
stream <- llm$stream_async(input$assistant_user_input)
|
|
84
|
+
chat_append("assistant", stream)
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
shinyApp(ui, server)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Typography, motion, and accessibility
|
|
92
|
+
|
|
93
|
+
Set `base_font` and `heading_font` in `bs_theme()` (e.g., `font_google(...)` or locally hosted fonts for air-gapped deployments). Prefer `input_task_button` and `withProgress` over decorative motion, and honor `prefers-reduced-motion` in custom CSS. Provide labels for every input, use `validate(need(...))` so empty or invalid states display clear copy instead of blank containers, and add text/table alternatives alongside plots.
|
|
94
|
+
|
|
95
|
+
## States and forms idiom
|
|
96
|
+
|
|
97
|
+
- Choose `bindCache(..., cache = "session")` for tenant- or user-private queries; reserve `cache = "app"` strictly for public/shared data.
|
|
98
|
+
- Encapsulate reusable panels with `NS(id)` + `moduleServer(id, ...)` to prevent input/output ID collisions.
|
|
99
|
+
- Never run heavy blocking R computations directly inside `renderPlot`/`observeEvent` on shared workers—offload them via `ExtendedTask` + `mirai`.
|
|
100
|
+
- Preserve form inputs across reactive updates (`shinyvalidate::InputValidator` for inline field validation) and validate uploaded files (`fileInput`) by size and MIME/extension before parsing.
|
|
101
|
+
|
|
102
|
+
## Do/don't pairs
|
|
103
|
+
|
|
104
|
+
| Do | Don't |
|
|
105
|
+
|---|---|
|
|
106
|
+
| `ExtendedTask` + `mirai` + `bind_task_button()` for slow R jobs | Blocking the single R process for every connected user |
|
|
107
|
+
| `bindCache(..., cache = "session")` for private user queries | Sharing user-specific rows in `cache = "app"` |
|
|
108
|
+
| `NS(id)` + `moduleServer()` for repeated panels | Copy-pasting global input IDs like `region1`, `region2` |
|
|
109
|
+
| `validate(need(nrow(df) > 0, "..."))` explicit empty/error copy | Bare `req()` silently leaving a blank card |
|
|
110
|
+
| `bs_theme(version = 5, ...)` + `thematic_shiny()` + `input_dark_mode()` | Hardcoded ggplot light theme clashing with dark mode |
|
|
111
|
+
|
|
112
|
+
## Known traps
|
|
113
|
+
|
|
114
|
+
Cross-session leakage from global variables or `cache = "app"`, blocking workers without `ExtendedTask`/`mirai`, reactive invalidation loops, un-namespaced IDs inside modules, forgetting `daemons(0)` cleanup on stop, and plot themes ignoring `input_dark_mode()`.
|
|
115
|
+
|
|
116
|
+
## Verification commands
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
Rscript -e 'shiny::runApp()'
|
|
120
|
+
Rscript -e 'testthat::test_dir("tests")'
|
|
121
|
+
Rscript -e 'shinytest2::test_app()'
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`testthat::test_dir("tests")` and `shiny::testServer()` verify reactive server logic (`static`/unit evidence); `shinytest2::test_app()` (requires `shinytest2` and Chromium) and interactive browser inspection across light/dark modes and narrow widths provide `rendered` evidence.
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Reactive Python data apps and notebooks (marimo, Solara, Mesop, Taipy)
|
|
2
|
+
|
|
3
|
+
When top-to-bottom script reruns or Jupyter's out-of-order hidden state cause bugs, choose a **reactive DAG, component-scoped, or scenario-driven Python framework**.
|
|
4
|
+
|
|
5
|
+
## Framework decision matrix
|
|
6
|
+
|
|
7
|
+
| Framework | Execution model | Source format | Best fit | Primary trade-off |
|
|
8
|
+
|---|---|---|---|---|
|
|
9
|
+
| **marimo** | Reactive dependency DAG (cells re-run deterministically on input change) | Pure Git-friendly `.py` files (`@app.cell`) | Reproducible notebooks, DuckDB SQL exploration, zero-hidden-state web apps, WASM exports | Global variable names must be unique across cells; circular references are disallowed |
|
|
10
|
+
| **Solara** | React-like component tree (`@solara.component` + `solara.reactive`) over ipywidgets/Vuetify | Standard Python modules | Stateful multi-page data apps reusing Jupyter/AnyWidget/Altair/Plotly ecosystems | React hook rules (`use_state`, `use_effect`, `use_task`) differ from linear scripts |
|
|
11
|
+
| **Mesop** | Typed Python UI (`@me.stateclass` + `@me.page`) rendered with Angular Material components | Pure Python | Internal AI/ML eval tools and rapid Python-only web apps with zero JS build | Opinionated Material styling; custom JS requires web component wrappers |
|
|
12
|
+
| **Taipy** | Pipeline/scenario DAG (`taipy.Core`) + reactive GUI (`taipy.gui`) | Python + Builder (`tgb`) or Markdown | Enterprise operations, what-if scenario comparison, scheduled pipelines + dashboards | Heavier project architecture than lightweight single-file tools |
|
|
13
|
+
|
|
14
|
+
## marimo idioms
|
|
15
|
+
|
|
16
|
+
- Bind widgets (`mo.ui.slider`, `mo.ui.table`, `mo.ui.dropdown`, `mo.ui.anywidget`) in one cell and read `.value` downstream. Set `debounce=True` on sliders driving SQL or ML queries.
|
|
17
|
+
- Query DataFrames and Parquet files directly with `mo.sql` (DuckDB engine), cache expensive steps with `@mo.cache` / `@mo.persistent_cache`, and reserve `mo.state` only for synced multi-control edits that a pure DAG cannot express.
|
|
18
|
+
- Configure notebook appearance via `marimo.App(width="medium", css_file="custom.css")` and serve end-user apps read-only with `marimo run app.py` or static Pyodide WASM via `marimo export html-wasm app.py -o dist --mode run`.
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
import marimo as mo
|
|
22
|
+
import altair as alt
|
|
23
|
+
|
|
24
|
+
threshold = mo.ui.slider(0.0, 1.0, step=0.05, value=0.5, debounce=True, label="Threshold")
|
|
25
|
+
filtered = mo.sql(f"SELECT region, score FROM scores_df WHERE score >= {threshold.value}")
|
|
26
|
+
|
|
27
|
+
@mo.cache
|
|
28
|
+
def expensive_summary(min_score: float):
|
|
29
|
+
return run_heavy_agg(min_score)
|
|
30
|
+
|
|
31
|
+
# Embed any AnyWidget bidirectionally inside the reactive DAG:
|
|
32
|
+
widget = mo.ui.anywidget(MyCustomAnyWidget(threshold=threshold.value))
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Solara idioms
|
|
36
|
+
|
|
37
|
+
Scope per-user reactive state with `solara.reactive` (for app/session stores) or `solara.use_state` (component-local), offload slow queries with `solara.use_task`, and map palette tokens through `solara.lab.theme`:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
import solara
|
|
41
|
+
import solara.lab
|
|
42
|
+
|
|
43
|
+
solara.lab.theme.themes.light.primary = "#0074ca"
|
|
44
|
+
solara.lab.theme.dark = False
|
|
45
|
+
selected_region = solara.reactive("EMEA")
|
|
46
|
+
|
|
47
|
+
@solara.component
|
|
48
|
+
def Page():
|
|
49
|
+
task = solara.use_task(lambda: fetch_region_df(selected_region.value), dependencies=[selected_region.value])
|
|
50
|
+
with solara.AppLayout(title="Operations"):
|
|
51
|
+
with solara.Sidebar():
|
|
52
|
+
solara.Select(label="Region", value=selected_region, values=["EMEA", "AMER", "APAC"])
|
|
53
|
+
solara.lab.ThemeToggle()
|
|
54
|
+
if task.pending:
|
|
55
|
+
solara.ProgressLinear(True)
|
|
56
|
+
elif task.error:
|
|
57
|
+
solara.Error(f"Query failed: {task.exception}")
|
|
58
|
+
elif task.value.empty:
|
|
59
|
+
solara.Info("No records match the active filter.")
|
|
60
|
+
else:
|
|
61
|
+
solara.DataFrame(task.value)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Mesop idioms
|
|
65
|
+
|
|
66
|
+
Declare all serializable session state in a `@me.stateclass`, define pages with `@me.page`, read Material theme tokens via `me.theme_var(...)` + `me.set_theme_mode("system")`, and stream generator yields directly from event handlers:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import mesop as me
|
|
70
|
+
|
|
71
|
+
@me.stateclass
|
|
72
|
+
class State:
|
|
73
|
+
prompt: str = ""
|
|
74
|
+
response: str = ""
|
|
75
|
+
loading: bool = False
|
|
76
|
+
|
|
77
|
+
def on_run(e: me.ClickEvent):
|
|
78
|
+
state = me.state(State)
|
|
79
|
+
state.loading = True
|
|
80
|
+
state.response = ""
|
|
81
|
+
yield
|
|
82
|
+
for chunk in stream_eval(state.prompt):
|
|
83
|
+
state.response += chunk
|
|
84
|
+
yield
|
|
85
|
+
state.loading = False
|
|
86
|
+
|
|
87
|
+
@me.page(path="/", title="Eval Bench")
|
|
88
|
+
def page():
|
|
89
|
+
state = me.state(State)
|
|
90
|
+
with me.box(style=me.Style(padding=me.Padding.all(24), background=me.theme_var("surface"))):
|
|
91
|
+
me.input(label="Prompt", on_blur=lambda e: setattr(me.state(State), "prompt", e.value))
|
|
92
|
+
me.button("Run eval", type="flat", on_click=on_run, disabled=state.loading)
|
|
93
|
+
if state.loading:
|
|
94
|
+
me.progress_spinner()
|
|
95
|
+
me.markdown(state.response or "_Enter a prompt and run evaluation._")
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Taipy idioms
|
|
99
|
+
|
|
100
|
+
Separate **scenario/pipeline configuration** (`taipy.Config`) from **GUI state** (`taipy.gui.builder` `tgb`), and theme globally with `stylekit`:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
import taipy.gui.builder as tgb
|
|
104
|
+
from taipy.gui import Gui
|
|
105
|
+
|
|
106
|
+
threshold = 0.5
|
|
107
|
+
chart_df = load_initial_df()
|
|
108
|
+
|
|
109
|
+
def on_threshold_change(state):
|
|
110
|
+
state.chart_df = filter_df(state.threshold)
|
|
111
|
+
|
|
112
|
+
with tgb.Page() as page:
|
|
113
|
+
tgb.text("# Demand Forecast", mode="md")
|
|
114
|
+
tgb.slider("{threshold}", min=0.0, max=1.0, step=0.05, on_change=on_threshold_change)
|
|
115
|
+
tgb.chart("{chart_df}", x="date", y="demand", type="bar")
|
|
116
|
+
|
|
117
|
+
Gui(page=page).run(
|
|
118
|
+
stylekit={"color_primary": "#0074ca", "color_background_light": "#faf8f1"}
|
|
119
|
+
)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
For multi-user scenario workflows (`tp.create_scenario`, `tp.submit`), attach `tgb.scenario_selector` / `tgb.scenario` / `tgb.job_selector` so job status and data node lineage stay inspectable.
|
|
123
|
+
|
|
124
|
+
## Polars & Narwhals dataframe-agnostic integration
|
|
125
|
+
|
|
126
|
+
Never serialize multi-million-row eager DataFrames into browser JSON, WebSockets, or widget props just to render a 12-bar chart or paginated table:
|
|
127
|
+
|
|
128
|
+
- **Polars lazy & streaming queries**: read Parquet/CSV lazily with `pl.scan_parquet(...)` (or `.lazy()`), push filter predicates, column projections, and `group_by().agg(...)` reductions down into Polars, and call `.collect(engine="streaming")` only on the bounded UI result set (e.g., aggregated bins or top-N rows + total count).
|
|
129
|
+
- **Narwhals (`narwhals`)**: wrap shared chart/table preparation helpers with `@nw.narwhalify` (or `nw.from_native(df)`) so one component accepts **Polars, Pandas, PyArrow, DuckDB, or Modin** natively without calling `.to_pandas()` copies that spike server RAM.
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
import narwhals as nw
|
|
133
|
+
import polars as pl
|
|
134
|
+
from narwhals.typing import IntoFrameT
|
|
135
|
+
|
|
136
|
+
# Push heavy filtering/aggregation into Polars streaming engine before touching UI
|
|
137
|
+
def query_region_totals(path: str, min_score: float) -> pl.DataFrame:
|
|
138
|
+
return (
|
|
139
|
+
pl.scan_parquet(path)
|
|
140
|
+
.filter(pl.col("score") >= min_score)
|
|
141
|
+
.group_by("region")
|
|
142
|
+
.agg(pl.len().alias("rows"), pl.col("score").mean().alias("avg_score"))
|
|
143
|
+
.sort("avg_score", descending=True)
|
|
144
|
+
.collect(engine="streaming")
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
# Dataframe-agnostic UI prep helper (works identically on Polars, Pandas, PyArrow, DuckDB)
|
|
148
|
+
@nw.narwhalify
|
|
149
|
+
def top_regions(df: IntoFrameT, limit: int = 10) -> IntoFrameT:
|
|
150
|
+
return df.sort("avg_score", descending=True).head(limit)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
- **Perceptual time-series downsampling (`Min-Max` / `LTTB`)**: when plotting `10k–1M+` telemetry rows, bucket timestamps into `~1,000–2,000` pixel-aligned windows using **`Min-Max` envelopes** (`group_by_dynamic` emitting `[first, min, max, last]` per bucket) or **`LTTB`**—never use `df.gather_every(n)` (`every-Nth` slicing), which drops incident spikes!
|
|
154
|
+
- **Preserve `0` vs `null` and freshness metadata**: never call `.fill_null(0)` before charting or table display unless missingness literally equals zero in domain math; compute `max(event_ts)` alongside the query so the UI renders an explicit `UTC`/local timezone and **Data Freshness / SLA Staleness badge**.
|
|
155
|
+
|
|
156
|
+
## Do/don't pairs
|
|
157
|
+
|
|
158
|
+
| Do | Don't |
|
|
159
|
+
|---|---|
|
|
160
|
+
| `debounce=True` on marimo sliders driving SQL or ML cells | Recompute heavy DAG branches on every pixel of a drag |
|
|
161
|
+
| Keep marimo notebooks in Git as `.py` and run `marimo check` | Rely on hidden out-of-order execution state |
|
|
162
|
+
| Push filters, `Min-Max`/`LTTB` downsampling, and aggregations into Polars LazyFrame/streaming or DuckDB | Use `df.gather_every(n)` (erasing spikes), call `.fill_null(0)` blindly, or serialize raw million-row DataFrames over WebSockets |
|
|
163
|
+
| Offload slow Solara work to `solara.use_task` with error/pending UI | Block the Solara render function with synchronous network calls |
|
|
164
|
+
| Keep Mesop session state serializable in `@me.stateclass` | Mutate module-level globals shared across concurrent Mesop users |
|
|
165
|
+
| Style Taipy via `stylekit` and explicit `state.*` updates | Mutate global DataFrames without notifying `state` |
|
|
166
|
+
|
|
167
|
+
## Verification commands
|
|
168
|
+
|
|
169
|
+
```sh
|
|
170
|
+
# marimo
|
|
171
|
+
marimo check app.py
|
|
172
|
+
marimo run app.py
|
|
173
|
+
marimo export html-wasm app.py -o dist --mode run
|
|
174
|
+
|
|
175
|
+
# Solara
|
|
176
|
+
solara run app.py
|
|
177
|
+
python -m pytest
|
|
178
|
+
|
|
179
|
+
# Mesop
|
|
180
|
+
mesop app.py
|
|
181
|
+
|
|
182
|
+
# Taipy
|
|
183
|
+
taipy run app.py
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
`marimo check` and `pytest` unit tests provide `static`/logic evidence; inspecting live filter updates, pending/error states, theme contrast, and narrow viewports in a real browser provides `rendered` evidence.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Reflex
|
|
2
|
+
|
|
3
|
+
## Token mapping
|
|
4
|
+
|
|
5
|
+
Configure global appearance, accent, gray scale, and radius on `rx.App(theme=rx.theme(...))` (backed by Radix Themes), and centralize semantic style tokens in a Python constants module rather than scattering inline style dicts across components:
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
import reflex as rx
|
|
9
|
+
|
|
10
|
+
app = rx.App(
|
|
11
|
+
theme=rx.theme(
|
|
12
|
+
appearance="inherit", # respects system light/dark or rx.color_mode
|
|
13
|
+
has_background=True,
|
|
14
|
+
radius="medium",
|
|
15
|
+
accent_color="blue",
|
|
16
|
+
gray_color="slate",
|
|
17
|
+
)
|
|
18
|
+
)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Reactive state, `@rx.event`, background tasks, and control flow
|
|
22
|
+
|
|
23
|
+
Reflex compiles Python UI definitions into a React/Vite frontend paired with a FastAPI/WebSocket state backend. Always use Reflex's reactive primitives (`@rx.event`, `@rx.var(cache=True)`, `rx.foreach`, `rx.cond`, `rx.match`, `rx.ComponentState`) instead of plain Python `if`/`for` on state vars:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import reflex as rx
|
|
27
|
+
|
|
28
|
+
class MetricsState(rx.State):
|
|
29
|
+
region: str = "EMEA"
|
|
30
|
+
rows: list[dict[str, str]] = []
|
|
31
|
+
status: str = "idle" # "idle" | "loading" | "error" | "ready"
|
|
32
|
+
error_message: str = ""
|
|
33
|
+
|
|
34
|
+
@rx.var(cache=True)
|
|
35
|
+
def row_count(self) -> int:
|
|
36
|
+
return len(self.rows)
|
|
37
|
+
|
|
38
|
+
@rx.event
|
|
39
|
+
def set_region(self, value: str):
|
|
40
|
+
self.region = value
|
|
41
|
+
|
|
42
|
+
@rx.event(background=True)
|
|
43
|
+
async def refresh_rows(self):
|
|
44
|
+
async with self:
|
|
45
|
+
self.status = "loading"
|
|
46
|
+
self.error_message = ""
|
|
47
|
+
try:
|
|
48
|
+
data = await fetch_region_rows_async(self.region)
|
|
49
|
+
async with self:
|
|
50
|
+
self.rows = data
|
|
51
|
+
self.status = "ready"
|
|
52
|
+
except Exception as exc:
|
|
53
|
+
async with self:
|
|
54
|
+
self.error_message = str(exc)
|
|
55
|
+
self.status = "error"
|
|
56
|
+
|
|
57
|
+
def metrics_view() -> rx.Component:
|
|
58
|
+
return rx.vstack(
|
|
59
|
+
rx.hstack(
|
|
60
|
+
rx.select(["EMEA", "AMER", "APAC"], value=MetricsState.region, on_change=MetricsState.set_region),
|
|
61
|
+
rx.button("Load", on_click=MetricsState.refresh_rows, loading=MetricsState.status == "loading"),
|
|
62
|
+
),
|
|
63
|
+
rx.match(
|
|
64
|
+
MetricsState.status,
|
|
65
|
+
("loading", rx.spinner(size="3")),
|
|
66
|
+
("error", rx.callout(MetricsState.error_message, color_scheme="red")),
|
|
67
|
+
(
|
|
68
|
+
"ready",
|
|
69
|
+
rx.cond(
|
|
70
|
+
MetricsState.row_count > 0,
|
|
71
|
+
rx.foreach(MetricsState.rows, lambda r: rx.text(f"{r['id']}: {r['total']}")),
|
|
72
|
+
rx.text("No records match the selected region."),
|
|
73
|
+
),
|
|
74
|
+
),
|
|
75
|
+
rx.text("Select a region and load data."),
|
|
76
|
+
),
|
|
77
|
+
)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- **`@rx.event`**: Mark every UI-invocable state method explicitly with `@rx.event` so backend state boundaries stay auditable and safe.
|
|
81
|
+
- **`@rx.event(background=True)`**: Offload slow I/O, LLM streaming, or warehouse queries to background tasks; mutate `self.*` strictly inside `async with self:` blocks so the client can stay interactive while work runs.
|
|
82
|
+
- **`@rx.var(cache=True)`**: Cache derived computed vars so expensive filters or aggregations only recompute when their tracked dependencies change.
|
|
83
|
+
- **`rx.ComponentState`**: Use `class FilterCard(rx.ComponentState)` when rendering multiple independent instances of a stateful widget (editable cards, modals, inline drawers) so each instance gets isolated state automatically without manual dictionary keys.
|
|
84
|
+
|
|
85
|
+
## Layout, typography, motion, and accessibility
|
|
86
|
+
|
|
87
|
+
Use responsive Radix layout props (`columns=rx.breakpoints(initial="1", md="2", lg="3")`) rather than fixed desktop widths. Load custom fonts via `stylesheets=[...]` on `rx.App(...)` and respect `prefers-reduced-motion` in custom CSS. Verify real DOM labels, keyboard focus order, disabled/loading states, and contrast on Radix/custom components rather than assuming Python wrappers guarantee accessibility.
|
|
88
|
+
|
|
89
|
+
## Forms idiom
|
|
90
|
+
|
|
91
|
+
Prefer `rx.form(..., on_submit=State.handle_submit)` for multi-field mutations so form inputs do not incur websocket roundtrips on every keystroke. Preserve failed drafts in state and show validation copy adjacent to the offending field rather than toast-only alerts.
|
|
92
|
+
|
|
93
|
+
## Do/don't pairs
|
|
94
|
+
|
|
95
|
+
| Do | Don't |
|
|
96
|
+
|---|---|
|
|
97
|
+
| `@rx.event` on handlers and `@rx.event(background=True)` for slow I/O | Blocking the default state lock with long synchronous queries |
|
|
98
|
+
| `rx.cond`, `rx.match`, `rx.foreach` over reactive `Var`s | Python `if State.flag:` or `for item in State.rows:` inside render |
|
|
99
|
+
| `@rx.var(cache=True)` for expensive derived values | Recomputing heavy aggregations on every unrelated state tick |
|
|
100
|
+
| `rx.ComponentState` for repeatable stateful widgets | Sharing one global state singleton across multiple widget instances |
|
|
101
|
+
| `rx.form(on_submit=...)` to batch edits | Sending websocket `on_change` events per keystroke on large forms |
|
|
102
|
+
|
|
103
|
+
## Known traps
|
|
104
|
+
|
|
105
|
+
Mutating `self` outside `async with self:` inside a background event, placing unserializable database connections on `rx.State` (keep them module/pool-level or underscore-prefixed private backend vars), websocket disconnects without visible state, oversized state payloads serialized on every delta, and forgetting `cache=True` on heavy computed vars.
|
|
106
|
+
|
|
107
|
+
## Verification commands
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
python -m compileall .
|
|
111
|
+
python -m pytest
|
|
112
|
+
reflex run
|
|
113
|
+
reflex export --frontend-only
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`reflex export` validates frontend compilation (`static`), and `pytest` checks state logic (`static`); inspect rendered browser views, responsive breakpoints, dark mode, and websocket state transitions for `rendered` evidence.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Shiny for Python
|
|
2
|
+
|
|
3
|
+
## Token mapping
|
|
4
|
+
|
|
5
|
+
Use `ui.Theme` (backed by Bootstrap 5 / Bootswatch Sass compilation) for semantic colors, typography, and spacing, paired with `ui.input_dark_mode()` and scoped CSS files under `www/`. Synchronize Matplotlib/Plotly/Altair figure styles separately because plotting libraries do not automatically inherit Bootstrap CSS variables.
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from shiny import ui
|
|
9
|
+
|
|
10
|
+
app_theme = (
|
|
11
|
+
ui.Theme("flatly")
|
|
12
|
+
.add_defaults(
|
|
13
|
+
primary="#0074ca",
|
|
14
|
+
body_bg="#faf8f1",
|
|
15
|
+
body_color="#161b24",
|
|
16
|
+
)
|
|
17
|
+
.add_rules(".metric-note { font-variant-numeric: tabular-nums; }")
|
|
18
|
+
)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Express vs Core architecture
|
|
22
|
+
|
|
23
|
+
Choose the API surface that matches app complexity rather than mixing them randomly:
|
|
24
|
+
|
|
25
|
+
| Mode | Entry idiom | Best fit | Trade-off |
|
|
26
|
+
|---|---|---|---|
|
|
27
|
+
| **Shiny Express** | `from shiny.express import input, render, ui` | Rapid single-file prototypes, notebook-like top-to-bottom apps | Implicit UI ordering makes large modular apps harder to test and share |
|
|
28
|
+
| **Shiny Core** | `App(app_ui, server)` + `@module.ui` / `@module.server` | Production multi-page dashboards, reusable modules, strict separation of layout and reactive server graph | Slightly more boilerplate for tiny demos |
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
# Shiny Core with non-blocking ExtendedTask and streaming ui.Chat
|
|
32
|
+
import asyncio
|
|
33
|
+
from shiny import App, reactive, render, ui
|
|
34
|
+
|
|
35
|
+
app_ui = ui.page_sidebar(
|
|
36
|
+
ui.sidebar(
|
|
37
|
+
ui.input_select("region", "Region", ["EMEA", "AMER", "APAC"]),
|
|
38
|
+
ui.input_task_button("run_forecast", "Run forecast"),
|
|
39
|
+
ui.input_dark_mode(),
|
|
40
|
+
),
|
|
41
|
+
ui.layout_columns(
|
|
42
|
+
ui.card(ui.card_header("Forecast"), ui.output_data_frame("forecast_tbl")),
|
|
43
|
+
ui.card(ui.card_header("Analyst assistant"), ui.chat_ui("assistant")),
|
|
44
|
+
),
|
|
45
|
+
title="Revenue Forecast",
|
|
46
|
+
theme=app_theme,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
def server(input, output, session):
|
|
50
|
+
@ui.bind_task_button(button_id="run_forecast")
|
|
51
|
+
@reactive.extended_task
|
|
52
|
+
async def compute_forecast(region: str):
|
|
53
|
+
await asyncio.sleep(0.1) # replace with async I/O or ThreadPoolExecutor work
|
|
54
|
+
return run_model_for_region(region)
|
|
55
|
+
|
|
56
|
+
@reactive.effect
|
|
57
|
+
@reactive.event(input.run_forecast)
|
|
58
|
+
def _start_forecast():
|
|
59
|
+
compute_forecast(input.region())
|
|
60
|
+
|
|
61
|
+
@render.data_frame
|
|
62
|
+
def forecast_tbl():
|
|
63
|
+
return render.DataGrid(compute_forecast.result())
|
|
64
|
+
|
|
65
|
+
chat = ui.Chat(id="assistant")
|
|
66
|
+
|
|
67
|
+
@chat.on_user_submit
|
|
68
|
+
async def _handle_chat(user_input: str):
|
|
69
|
+
await chat.append_message_stream(stream_llm_chunks(user_input))
|
|
70
|
+
|
|
71
|
+
app = App(app_ui, server)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Layout, responsiveness, and Shinylive (WASM)
|
|
75
|
+
|
|
76
|
+
- Build responsive layouts with `ui.page_sidebar`, `ui.page_navbar`, `ui.layout_columns(col_widths=...)`, `ui.card(full_screen=True)`, and `ui.value_box`. Reserve stable heights for reactive outputs so charts do not jump on recalculation.
|
|
77
|
+
- For zero-server static distribution (docs, demos, public reports), export to **Shinylive (Pyodide/WebAssembly)** with `shinylive export app site`. Verify every dependency has a pure-Python or Pyodide wheel, keep all secrets out of client code, and show an honest loading state while the WASM runtime initializes.
|
|
78
|
+
|
|
79
|
+
## Typography, motion, and accessibility
|
|
80
|
+
|
|
81
|
+
Load custom fonts via `ui.Theme` / `ui.head_content` with explicit fallbacks and `tabular-nums` for KPIs. Prefer reactive busy indicators (`ui.input_task_button`, `ui.Progress`) over decorative motion, and honor `prefers-reduced-motion` in custom CSS. Ensure inputs have real labels, plots include text/table alternatives, and focus does not vanish when dynamic UI rerenders.
|
|
82
|
+
|
|
83
|
+
## States and forms idiom
|
|
84
|
+
|
|
85
|
+
Separate reactive calculations (`@reactive.calc`), side effects (`@reactive.effect`), and non-blocking jobs (`@reactive.extended_task`). Use `req(...)` or explicit empty/error UI panels so invalid filters never silently blank an output without explanation. Isolate per-user state inside `server(...)` (or `reactive.value` per session); never mutate module-level globals across concurrent users.
|
|
86
|
+
|
|
87
|
+
## Do/don't pairs
|
|
88
|
+
|
|
89
|
+
| Do | Don't |
|
|
90
|
+
|---|---|
|
|
91
|
+
| `ui.Theme(...)` + `ui.input_dark_mode()` | Scattering inline CSS overrides across every component |
|
|
92
|
+
| `@reactive.extended_task` + `ui.input_task_button` for slow work | Blocking the shared asyncio loop with synchronous CPU/DB calls |
|
|
93
|
+
| Shiny Core + `@module.ui`/`@module.server` for multi-view apps | Growing a 1,500-line single-file Express script with name collisions |
|
|
94
|
+
| `ui.Chat` + `append_message_stream` for streaming responses | Re-rendering an entire markdown blob on every token |
|
|
95
|
+
| Explicit empty/error message when a query returns zero rows | Silent blank output caused by bare `req()` without user copy |
|
|
96
|
+
|
|
97
|
+
## Known traps
|
|
98
|
+
|
|
99
|
+
Blocking the event loop without `ExtendedTask`/executor offloading, mutating module globals across sessions, plot themes ignoring dark mode, Shinylive builds failing on C-extension packages or leaking credentials, and focus loss during dynamic `render.ui` redraws.
|
|
100
|
+
|
|
101
|
+
## Verification commands
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
python -m compileall .
|
|
105
|
+
python -m pytest
|
|
106
|
+
shiny run app.py
|
|
107
|
+
shinylive export app site
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Run `pytest` with Playwright (`shiny.playwright` / `shiny.pytest`) and inspect narrow/desktop layouts, dark mode, and empty/error states in a browser for `rendered` evidence; compilation alone is `static`.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Streamlit
|
|
2
|
+
|
|
3
|
+
## Token mapping
|
|
4
|
+
|
|
5
|
+
Configure `.streamlit/config.toml` first using `[theme]`, `[theme.sidebar]`, and light/dark sections (`primaryColor`, `backgroundColor`, `secondaryBackgroundColor`, `textColor`, `linkColor`, `font`, `fontFaces`, `baseFontSize`, chart palettes):
|
|
6
|
+
|
|
7
|
+
```toml
|
|
8
|
+
[theme]
|
|
9
|
+
base = "light"
|
|
10
|
+
primaryColor = "#0074ca"
|
|
11
|
+
backgroundColor = "#faf8f1"
|
|
12
|
+
secondaryBackgroundColor = "#f1eee4"
|
|
13
|
+
textColor = "#161b24"
|
|
14
|
+
linkColor = "#005a9e"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Map semantic tokens deliberately; primary color alone is not a design system. Reach for scoped custom CSS only when `.streamlit/config.toml` cannot express a structural requirement, and never rely on autogenerated emotion/st-emotion class hashes.
|
|
18
|
+
|
|
19
|
+
## Layout, navigation, and responsive idioms
|
|
20
|
+
|
|
21
|
+
Use `st.navigation` with `st.Page` for multipage apps so shared chrome, auth gates, and global filters live in one entrypoint instead of fragile `pages/` filename sorting:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
import streamlit as st
|
|
25
|
+
|
|
26
|
+
nav = st.navigation({
|
|
27
|
+
"Analytics": [
|
|
28
|
+
st.Page("views/overview.py", title="Overview", default=True),
|
|
29
|
+
st.Page("views/cohorts.py", title="Cohorts"),
|
|
30
|
+
],
|
|
31
|
+
"Operations": [st.Page("views/audit.py", title="Audit Log")],
|
|
32
|
+
})
|
|
33
|
+
nav.run()
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Size dataframes, charts, buttons, and containers with `width="stretch"` or `width="content"` (or an explicit pixel integer) rather than the deprecated `use_container_width` argument:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
st.dataframe(df, width="stretch", hide_index=True)
|
|
40
|
+
st.plotly_chart(fig, width="stretch")
|
|
41
|
+
st.button("Export CSV", width="content")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Avoid deeply nested `st.columns` that crush on narrow viewports. Keep `st.sidebar` focused on controls or navigation, never overloaded with both.
|
|
45
|
+
|
|
46
|
+
## Caching, connections, fragments, and chat
|
|
47
|
+
|
|
48
|
+
Separate serializable data caching from singleton resource caching, isolate high-frequency subtrees with `@st.fragment`, and stream conversational responses with `st.chat_message` + `st.write_stream`:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
import streamlit as st
|
|
52
|
+
|
|
53
|
+
conn = st.connection("warehouse", type="sql")
|
|
54
|
+
|
|
55
|
+
@st.cache_data(ttl=300, show_spinner="Loading daily metrics...")
|
|
56
|
+
def load_metrics(region: str):
|
|
57
|
+
return conn.query(
|
|
58
|
+
"SELECT day, revenue FROM daily_metrics WHERE region = :region",
|
|
59
|
+
params={"region": region},
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
@st.cache_resource
|
|
63
|
+
def load_model():
|
|
64
|
+
return init_heavy_embedding_model()
|
|
65
|
+
|
|
66
|
+
@st.fragment
|
|
67
|
+
def live_filter_panel():
|
|
68
|
+
region = st.selectbox("Region", ["EMEA", "AMER", "APAC"], key="region")
|
|
69
|
+
df = load_metrics(region)
|
|
70
|
+
if df.empty:
|
|
71
|
+
st.info("No rows for this region.")
|
|
72
|
+
return
|
|
73
|
+
st.dataframe(df, width="stretch")
|
|
74
|
+
|
|
75
|
+
with st.chat_message("assistant"):
|
|
76
|
+
st.write_stream(stream_answer_chunks(prompt))
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- Use `@st.fragment` (and optional `run_every="30s"` for polling) so interacting with one chart or table does not rerun the whole script. Call `st.rerun(scope="app")` only when a fragment must update outer state.
|
|
80
|
+
- Use `st.components.v2` (`st.components.v2.component`) for new bidirectional custom web components that need direct DOM/CSS integration and typed state hooks instead of legacy iframe-only v1 wrappers.
|
|
81
|
+
|
|
82
|
+
## Typography, motion, and accessibility
|
|
83
|
+
|
|
84
|
+
Use `fontFaces` / `baseFontSize` in `.streamlit/config.toml` for typography. Use `st.status`, `st.progress`, and `st.toast` truthfully for long-running work; custom CSS animation must honor `prefers-reduced-motion`. Always provide widget labels (use `label_visibility="collapsed"` rather than empty `""` so screen readers keep accessible names), pair charts with text takeaways or expandable data tables, and verify keyboard navigation and contrast in rendered output.
|
|
85
|
+
|
|
86
|
+
## Forms and states idiom
|
|
87
|
+
|
|
88
|
+
Every interaction triggers a rerun of either the fragment or the script. Initialize `st.session_state` explicitly, use stable `key`s, and wrap multi-field mutations in `st.form` so intermediate edits do not trigger expensive queries. Distinguish empty datasets (`df.empty`), missing credentials/secrets, validation errors, and stale cached results visibly.
|
|
89
|
+
|
|
90
|
+
## Do/don't pairs
|
|
91
|
+
|
|
92
|
+
| Do | Don't |
|
|
93
|
+
|---|---|
|
|
94
|
+
| `st.dataframe(df, width="stretch")` / `width="content"` | Deprecated `use_container_width=True` |
|
|
95
|
+
| `@st.fragment` around interactive filters or polling widgets | Rerunning expensive top-level setup on every filter change |
|
|
96
|
+
| `st.cache_data(ttl=...)` for DataFrames; `st.cache_resource` for models/connections | Storing per-user mutable state in global `st.cache_resource` |
|
|
97
|
+
| `st.navigation([st.Page(...)])` for shared multipage framing | Duplicating auth and sidebar boilerplate across `pages/*.py` |
|
|
98
|
+
| `st.connection(...)` with parameterized SQL queries | Interpolating widget values directly into SQL strings |
|
|
99
|
+
| `st.status(..., expanded=True)` reflecting real execution steps | Fake progress bars or silent spinners after an exception |
|
|
100
|
+
|
|
101
|
+
## Known traps
|
|
102
|
+
|
|
103
|
+
Full-script reruns wiping unkeyed inputs, duplicate widget keys, mutating objects returned from `st.cache_resource` across sessions, leaking secrets into client state, brittle `.st-emotion-cache-*` CSS selectors, sidebar overload, and uploaded `UploadedFile` buffers not rewound (`seek(0)`) on reread.
|
|
104
|
+
|
|
105
|
+
## Verification commands
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
python -m compileall .
|
|
109
|
+
python -m pytest
|
|
110
|
+
streamlit run app.py
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Write headless state and interaction tests with `streamlit.testing.v1.AppTest` (`AppTest.from_file("app.py").run()`) as `static`/logic evidence, and run Playwright or manual browser checks across narrow/desktop widths for `rendered` evidence.
|