axiom-coding-agent-setup 1.0.10 → 1.0.11
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/skills/agent-browser/SKILL.md +55 -0
- package/.agents/skills/developing-with-streamlit/SKILL.md +220 -0
- package/.agents/skills/developing-with-streamlit/skills/building-streamlit-chat-ui/SKILL.md +195 -0
- package/.agents/skills/developing-with-streamlit/skills/building-streamlit-custom-components-v2/SKILL.md +233 -0
- package/.agents/skills/developing-with-streamlit/skills/building-streamlit-custom-components-v2/references/packaged-components.md +212 -0
- package/.agents/skills/developing-with-streamlit/skills/building-streamlit-custom-components-v2/references/state-sync.md +149 -0
- package/.agents/skills/developing-with-streamlit/skills/building-streamlit-custom-components-v2/references/theme-css-variables.md +243 -0
- package/.agents/skills/developing-with-streamlit/skills/building-streamlit-custom-components-v2/references/troubleshooting.md +121 -0
- package/.agents/skills/developing-with-streamlit/skills/building-streamlit-dashboards/SKILL.md +147 -0
- package/.agents/skills/developing-with-streamlit/skills/building-streamlit-multipage-apps/SKILL.md +218 -0
- package/.agents/skills/developing-with-streamlit/skills/choosing-streamlit-selection-widgets/SKILL.md +139 -0
- package/.agents/skills/developing-with-streamlit/skills/connecting-streamlit-to-snowflake/SKILL.md +188 -0
- package/.agents/skills/developing-with-streamlit/skills/creating-streamlit-themes/SKILL.md +486 -0
- package/.agents/skills/developing-with-streamlit/skills/displaying-streamlit-data/SKILL.md +199 -0
- package/.agents/skills/developing-with-streamlit/skills/improving-streamlit-design/SKILL.md +191 -0
- package/.agents/skills/developing-with-streamlit/skills/optimizing-streamlit-performance/SKILL.md +323 -0
- package/.agents/skills/developing-with-streamlit/skills/organizing-streamlit-code/SKILL.md +91 -0
- package/.agents/skills/developing-with-streamlit/skills/setting-up-streamlit-environment/SKILL.md +128 -0
- package/.agents/skills/developing-with-streamlit/skills/using-streamlit-cli/SKILL.md +165 -0
- package/.agents/skills/developing-with-streamlit/skills/using-streamlit-custom-components/SKILL.md +170 -0
- package/.agents/skills/developing-with-streamlit/skills/using-streamlit-layouts/SKILL.md +229 -0
- package/.agents/skills/developing-with-streamlit/skills/using-streamlit-markdown/SKILL.md +207 -0
- package/.agents/skills/developing-with-streamlit/skills/using-streamlit-session-state/SKILL.md +144 -0
- package/.agents/skills/developing-with-streamlit/templates/.gitattributes +3 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/README.md +188 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-companies/pyproject.toml +12 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-companies/streamlit_app.py +365 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-compute/pyproject.toml +12 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-compute/streamlit_app.py +461 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-compute-snowflake/.streamlit/secrets.toml.example +20 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-compute-snowflake/pyproject.toml +11 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-compute-snowflake/snowflake.yml +18 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-compute-snowflake/streamlit_app.py +527 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-feature-usage/pyproject.toml +12 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-feature-usage/streamlit_app.py +307 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-metrics/pyproject.toml +12 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-metrics/streamlit_app.py +426 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-metrics-snowflake/.streamlit/secrets.toml.example +20 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-metrics-snowflake/pyproject.toml +11 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-metrics-snowflake/snowflake.yml +18 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-metrics-snowflake/streamlit_app.py +463 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-seattle-weather/pyproject.toml +12 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-seattle-weather/streamlit_app.py +252 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-stock-peers/pyproject.toml +12 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-stock-peers/streamlit_app.py +342 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-stock-peers-snowflake/.streamlit/secrets.toml.example +20 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-stock-peers-snowflake/pyproject.toml +11 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-stock-peers-snowflake/snowflake.yml +18 -0
- package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-stock-peers-snowflake/streamlit_app.py +384 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/README.md +128 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/_configs/dracula.toml +39 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/_configs/github.toml +37 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/_configs/minimal.toml +39 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/_configs/nord.toml +39 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/_configs/snowflake.toml +42 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/_configs/solarized-light.toml +38 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/_configs/spotify.toml +34 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/_configs/stripe.toml +35 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/_shared/streamlit_app.py +336 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/_templates/pyproject.toml.tmpl +12 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/dracula/.streamlit/config.toml +39 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/dracula/pyproject.toml +10 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/dracula/streamlit_app.py +337 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/github/.streamlit/config.toml +37 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/github/pyproject.toml +10 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/github/streamlit_app.py +337 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/manage.py +332 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/minimal/.streamlit/config.toml +39 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/minimal/pyproject.toml +10 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/minimal/streamlit_app.py +337 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/nord/.streamlit/config.toml +39 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/nord/pyproject.toml +10 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/nord/streamlit_app.py +337 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/snowflake/.streamlit/config.toml +42 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/snowflake/pyproject.toml +10 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/snowflake/streamlit_app.py +337 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/solarized-light/.streamlit/config.toml +38 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/solarized-light/pyproject.toml +10 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/solarized-light/streamlit_app.py +337 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/spotify/.streamlit/config.toml +34 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/spotify/pyproject.toml +10 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/spotify/streamlit_app.py +337 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/stripe/.streamlit/config.toml +35 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/stripe/pyproject.toml +10 -0
- package/.agents/skills/developing-with-streamlit/templates/themes/stripe/streamlit_app.py +337 -0
- package/.agents/skills/fastapi/SKILL.md +436 -0
- package/.agents/skills/fastapi/references/dependencies.md +142 -0
- package/.agents/skills/fastapi/references/other-tools.md +76 -0
- package/.agents/skills/fastapi/references/streaming.md +105 -0
- package/.agents/skills/frontend-design/LICENSE.txt +177 -0
- package/.agents/skills/frontend-design/SKILL.md +42 -0
- package/.agents/skills/gradio/SKILL.md +84 -0
- package/.agents/skills/gradio/references/api-signatures.md +115 -0
- package/.agents/skills/gradio/references/event-listeners.md +130 -0
- package/.agents/skills/gradio/references/examples.md +613 -0
- package/.agents/skills/ui-ux-pro-max/SKILL.md +659 -0
- package/.agents/skills/ui-ux-pro-max/data +1 -0
- package/.agents/skills/ui-ux-pro-max/scripts +1 -0
- package/.env.axiom +8 -0
- package/AGENTS.md +2 -1
- package/README.md +19 -3
- package/bin/cli.js +11 -1
- package/opencode.json +7 -4
- package/package.json +1 -1
- package/skills-lock.json +36 -0
- package/.agents/skills/n8n-patterns/SKILL.md +0 -272
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: using-streamlit-markdown
|
|
3
|
+
description: Covers all Markdown features in Streamlit including GitHub-flavored syntax plus Streamlit extensions like colored text, badges, Material icons, and LaTeX. Use when formatting text, labels, tooltips, or any text-rendering element.
|
|
4
|
+
license: Apache-2.0
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Using Markdown in Streamlit
|
|
8
|
+
|
|
9
|
+
Streamlit supports Markdown throughout its API—in `st.markdown()`, widget labels, help tooltips, metrics, `st.table()` cells, and more. Beyond standard GitHub-flavored Markdown, Streamlit adds colored text, badges, icons, and LaTeX.
|
|
10
|
+
|
|
11
|
+
## Quick reference
|
|
12
|
+
|
|
13
|
+
| Feature | Syntax | Example | Works in labels |
|
|
14
|
+
|---------|--------|---------|--------|
|
|
15
|
+
| Bold | `**text**` | `**Bold**` | ✓ |
|
|
16
|
+
| Italic | `*text*` | `*Italic*` | ✓ |
|
|
17
|
+
| Strikethrough | `~text~` | `~Strikethrough~` | ✓ |
|
|
18
|
+
| Inline code | `` `code` `` | `` `variable` `` | ✓ |
|
|
19
|
+
| Code block | ` ```lang...``` ` | ` ```python...``` ` | ✗ |
|
|
20
|
+
| Link | `[text](url)` | `[Streamlit](https://streamlit.io)` | ✓ |
|
|
21
|
+
| Image | `` | `` | ✓ |
|
|
22
|
+
| Heading | `# ` to `###### ` | `## Section` | ✗ |
|
|
23
|
+
| Blockquote | `> text` | `> Note` | ✗ |
|
|
24
|
+
| Horizontal rule | `---` | `---` | ✗ |
|
|
25
|
+
| Unordered list | `- item` | `- First`<br>`- Second` | ✗ |
|
|
26
|
+
| Ordered list | `1. item` | `1. First`<br>`2. Second` | ✗ |
|
|
27
|
+
| Task list | `- [ ]` / `- [x]` | `- [x] Done`<br>`- [ ] Todo` | ✗ |
|
|
28
|
+
| Table | `\| a \| b \|` | `\| H1 \| H2 \|`<br>`\|--\|--\|` | ✗ |
|
|
29
|
+
| Emoji | Direct or shortcode | `🎉` or `:tada:` | ✓ |
|
|
30
|
+
| Streamlit logo | `:streamlit:` | `:streamlit:` | ✓ |
|
|
31
|
+
| Material icon | `:material/icon_name:` | `:material/check_circle:` | ✓ |
|
|
32
|
+
| Colored text | `:color[text]` | `:red[Error]` | ✓ |
|
|
33
|
+
| Colored background | `:color-background[text]` | `:blue-background[Info]` | ✓ |
|
|
34
|
+
| Badge | `:color-badge[text]` | `:green-badge[Success]` | ✓ |
|
|
35
|
+
| Small text | `:small[text]` | `:small[footnote]` | ✓ |
|
|
36
|
+
| LaTeX (inline) | `$formula$` | `$ax^2 + bx + c$` | ✓ |
|
|
37
|
+
| LaTeX (block) | `$$formula$$` | `$$\int_0^1 x^2 dx$$` | ✗ |
|
|
38
|
+
|
|
39
|
+
## Where Markdown works
|
|
40
|
+
|
|
41
|
+
Markdown is supported in most places where text is rendered. Streamlit has three levels of markdown support:
|
|
42
|
+
|
|
43
|
+
**Full Markdown** — All syntax shown in the table above:
|
|
44
|
+
- `st.markdown()`, `st.write()`, `st.caption()`, `st.info()`, `st.warning()`, `st.error()`, `st.success()`, `st.table` cells and headers, tooltips (`help` parameter)
|
|
45
|
+
|
|
46
|
+
**Label subset** — Inline formatting only (see table above). Block elements (e.g. headings, lists, tables) are silently stripped:
|
|
47
|
+
- Widget and element labels (`st.button`, `st.checkbox`, `st.radio`, `st.expander`, `st.page_link`, etc.), `st.radio` and `st.select_slider` options, `st.tabs` names, `st.metric` label/value/delta, `st.title`, `st.header`, `st.subheader`, `st.image` caption, `st.dialog` title, `st.progress`, `st.spinner`.
|
|
48
|
+
|
|
49
|
+
**No Markdown** — Text displays literally:
|
|
50
|
+
- `st.text()`, `st.json()`, `st.dataframe()` / `st.data_editor()` cells, `st.selectbox` / `st.multiselect` options, input placeholders, `st.Page` titles, chart/map labels
|
|
51
|
+
|
|
52
|
+
## GitHub-flavored Markdown
|
|
53
|
+
|
|
54
|
+
Standard GFM syntax works as expected. Headings automatically get anchor links for navigation.
|
|
55
|
+
|
|
56
|
+
~~~python
|
|
57
|
+
st.markdown("""
|
|
58
|
+
# Heading
|
|
59
|
+
|
|
60
|
+
**Bold**, *italic*, ~~strikethrough~~, `inline code`, [links](url)
|
|
61
|
+
|
|
62
|
+
- Unordered list
|
|
63
|
+
- [x] Task list
|
|
64
|
+
|
|
65
|
+
| Column | Column |
|
|
66
|
+
|--------|--------|
|
|
67
|
+
| Cell | Cell |
|
|
68
|
+
|
|
69
|
+
> Blockquote
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
code_block = "with syntax highlighting"
|
|
73
|
+
```
|
|
74
|
+
""")
|
|
75
|
+
~~~
|
|
76
|
+
|
|
77
|
+
## Colored text, backgrounds, and badges
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
st.markdown(":red[Error] and :green[Success]") # Colored text
|
|
81
|
+
st.markdown(":blue-background[Highlighted]") # Colored background
|
|
82
|
+
st.markdown(":green-badge[Active] :red-badge[Inactive]") # Inline badges
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Available colors:** `red`, `orange`, `yellow`, `green`, `blue`, `violet`, `gray`/`grey`, `rainbow`, `primary`
|
|
86
|
+
|
|
87
|
+
Note: `rainbow` is not supported for backgrounds or badges. Standalone badges also available via `st.badge()`.
|
|
88
|
+
|
|
89
|
+
## Material icons
|
|
90
|
+
|
|
91
|
+
Use Google Material Symbols with `:material/icon_name:` syntax. Find icons at [fonts.google.com/icons](https://fonts.google.com/icons)
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
st.markdown(":material/check_circle: Complete")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Material icons also work in `icon` parameters across many elements (`st.button`, `st.expander`, `st.info`, etc.).
|
|
98
|
+
|
|
99
|
+
## Emojis
|
|
100
|
+
|
|
101
|
+
Both Unicode emojis (preferred) and shortcodes work.
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
st.markdown("Hello! 👋 :+1: :tada: :streamlit:")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Note:** Material icons are preferred over emojis for a more professional look.
|
|
108
|
+
|
|
109
|
+
## LaTeX math
|
|
110
|
+
|
|
111
|
+
Single `$` for inline, double `$$` for display mode. Inline math requires non-whitespace after `$` to avoid conflicts with currency (e.g., "$5" won't be parsed as math).
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
# Inline math
|
|
115
|
+
st.markdown("The quadratic formula is $x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}$")
|
|
116
|
+
|
|
117
|
+
# Display math (centered, larger)
|
|
118
|
+
st.markdown("""
|
|
119
|
+
$$
|
|
120
|
+
\\sum_{i=1}^{n} x_i = x_1 + x_2 + ... + x_n
|
|
121
|
+
$$
|
|
122
|
+
""")
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Images in Markdown
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
st.markdown("")
|
|
129
|
+
st.button(" Click me") # Image as icon in label
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
In labels, images display as icons with max height equal to font height.
|
|
133
|
+
|
|
134
|
+
## Markdown in element labels
|
|
135
|
+
|
|
136
|
+
Widgets, containers, and other elements support Markdown in their labels (using the label subset).
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
st.radio(":material/palette: Choose **color**", [":red-background[Red]", ":blue-background[Blue]", ":green-background[Green]"])
|
|
140
|
+
tab1, tab2 = st.tabs([":material/home: Home", ":material/settings: Settings"])
|
|
141
|
+
st.metric(label=":material/attach_money: Revenue", value=":green[$1.2M]", delta=":material/trending_up: 12%")
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Escaping special characters
|
|
145
|
+
|
|
146
|
+
Use backslash to show literal characters: `\\[`, `\\*`, `1\\.`
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
st.markdown(":blue[Array: \\[1, 2, 3\\]]")
|
|
150
|
+
st.button("1\\. Not a list")
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Markdown in st.table
|
|
154
|
+
|
|
155
|
+
`st.table()` renders Markdown in cells and headers.
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
st.table({
|
|
159
|
+
"**Name**": "Alice",
|
|
160
|
+
"**Status**": ":green-badge[Active]",
|
|
161
|
+
"**Role**": ":material/shield: Admin"
|
|
162
|
+
})
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Combining features
|
|
166
|
+
|
|
167
|
+
Mix multiple features for rich formatting.
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
st.markdown("""
|
|
171
|
+
### :material/rocket: Launch status
|
|
172
|
+
|
|
173
|
+
| Phase | Status | Notes |
|
|
174
|
+
|-------|--------|-------|
|
|
175
|
+
| Build | :green-badge[Complete] | All tests passing |
|
|
176
|
+
| Deploy | :orange-badge[In Progress] | ETA: 2 hours |
|
|
177
|
+
| Monitor | :gray-badge[Pending] | Waiting on deploy |
|
|
178
|
+
|
|
179
|
+
:small[Last updated: just now]
|
|
180
|
+
""")
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## st.markdown - text alignment and width
|
|
184
|
+
|
|
185
|
+
Control layout with `text_alignment` and `width` parameters.
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
st.markdown("Centered heading", text_alignment="center") # left, center, right, justify
|
|
189
|
+
st.markdown("Content width only", width="content") # stretch, content, or pixels (e.g. 400)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## HTML (use very sparingly!)
|
|
193
|
+
|
|
194
|
+
Mix Markdown with HTML using `unsafe_allow_html=True`. For pure HTML without markdown processing, use `st.html()` instead.
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
st.markdown("**Status:** <span style='color: coral'>Custom styled</span>", unsafe_allow_html=True)
|
|
198
|
+
st.html("<div class='custom'>Pure HTML content</div>")
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## References
|
|
202
|
+
|
|
203
|
+
- [st.markdown](https://docs.streamlit.io/develop/api-reference/text/st.markdown)
|
|
204
|
+
- [st.latex](https://docs.streamlit.io/develop/api-reference/text/st.latex)
|
|
205
|
+
- [GitHub-flavored Markdown spec](https://github.github.com/gfm)
|
|
206
|
+
- [Material Symbols](https://fonts.google.com/icons)
|
|
207
|
+
- [KaTeX supported functions](https://katex.org/docs/supported.html)
|
package/.agents/skills/developing-with-streamlit/skills/using-streamlit-session-state/SKILL.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: using-streamlit-session-state
|
|
3
|
+
description: Using st.session_state to manage state across Streamlit reruns. Use when persisting data, handling widget state, implementing callbacks, or debugging state issues. Covers initialization patterns, widget-state association, and common gotchas.
|
|
4
|
+
license: Apache-2.0
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Using Streamlit session state
|
|
8
|
+
|
|
9
|
+
Streamlit reruns scripts top-to-bottom on every interaction. Without session state, variables reset each time. Use `st.session_state` to persist values across reruns.
|
|
10
|
+
|
|
11
|
+
## Basic usage
|
|
12
|
+
|
|
13
|
+
Session state is a dictionary-like object supporting attribute and bracket notation:
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
# Initialize with setdefault (preferred)
|
|
17
|
+
st.session_state.setdefault("count", 0)
|
|
18
|
+
|
|
19
|
+
# Alternative: check before setting
|
|
20
|
+
if "count" not in st.session_state:
|
|
21
|
+
st.session_state.count = 0
|
|
22
|
+
|
|
23
|
+
# Read
|
|
24
|
+
current = st.session_state.count
|
|
25
|
+
|
|
26
|
+
# Update
|
|
27
|
+
st.session_state.count += 1
|
|
28
|
+
st.session_state["count"] = 5 # Bracket notation also works
|
|
29
|
+
|
|
30
|
+
# Delete
|
|
31
|
+
del st.session_state.count
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Accessing uninitialized keys raises `KeyError`.** Use `st.session_state.get("key", default)` for safe access.
|
|
35
|
+
|
|
36
|
+
## Widget-state association
|
|
37
|
+
|
|
38
|
+
Every widget with a `key` parameter automatically syncs to session state:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
name = st.text_input("Name", key="user_name")
|
|
42
|
+
# st.session_state.user_name contains the same value as `name`
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Callbacks
|
|
46
|
+
|
|
47
|
+
Callbacks execute **before** the script reruns, allowing immediate state changes. Use `on_change` or `on_click` with optional `args` and `kwargs`:
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
def increment(amount):
|
|
51
|
+
st.session_state.count += amount
|
|
52
|
+
|
|
53
|
+
st.button("Add 5", on_click=increment, args=(5,))
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Access a widget's value in its own callback via `st.session_state.key`, not the return variable.
|
|
57
|
+
|
|
58
|
+
## Initialization patterns
|
|
59
|
+
|
|
60
|
+
Initialize all state at the top of your app for clarity:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
st.session_state.setdefault("user", None)
|
|
64
|
+
st.session_state.setdefault("page", "home")
|
|
65
|
+
st.session_state.setdefault("filters", {})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Multipage state
|
|
69
|
+
|
|
70
|
+
Widgets are NOT stateful across pages. Their values reset when navigating between pages.
|
|
71
|
+
|
|
72
|
+
### Sharing state
|
|
73
|
+
|
|
74
|
+
Use session state variables (not widget keys) to share data:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
# Page 1: Store value
|
|
78
|
+
st.session_state.selected_user = st.selectbox("User", users)
|
|
79
|
+
|
|
80
|
+
# Page 2: Read stored value
|
|
81
|
+
if "selected_user" in st.session_state:
|
|
82
|
+
st.write(f"Selected: {st.session_state.selected_user}")
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Shared widgets pattern
|
|
86
|
+
|
|
87
|
+
Put common widgets in the entrypoint file (before `nav.run()`):
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
# app.py (entrypoint)
|
|
91
|
+
with st.sidebar:
|
|
92
|
+
st.session_state.theme = st.selectbox("Theme", ["Light", "Dark"])
|
|
93
|
+
|
|
94
|
+
nav = st.navigation(pages)
|
|
95
|
+
nav.run()
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Common mistakes
|
|
99
|
+
|
|
100
|
+
### Module-level mutable state
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
# BAD: In imported modules, this is shared across ALL users
|
|
104
|
+
# utils.py
|
|
105
|
+
cache = {} # Persists across reruns AND users!
|
|
106
|
+
|
|
107
|
+
# GOOD: Use session state for per-user data
|
|
108
|
+
st.session_state.setdefault("cache", {})
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Modifying state after widget creation
|
|
112
|
+
|
|
113
|
+
Cannot assign to a widget's state after the widget has rendered:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
st.slider("Value", key="my_slider")
|
|
117
|
+
st.session_state.my_slider = 50 # Raises StreamlitAPIException!
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Mixing `value` parameter and session state
|
|
121
|
+
|
|
122
|
+
Don't set both—it causes warnings:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
# BAD: Conflicting sources
|
|
126
|
+
st.session_state.setdefault("name", "Alice")
|
|
127
|
+
st.text_input("Name", value="Bob", key="name") # Warning!
|
|
128
|
+
|
|
129
|
+
# GOOD: Use one or the other
|
|
130
|
+
st.session_state.setdefault("name", "Alice")
|
|
131
|
+
st.text_input("Name", key="name")
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Session characteristics
|
|
135
|
+
|
|
136
|
+
- **Per-user, per-tab**: Each browser tab has its own session
|
|
137
|
+
- **Temporary**: Lost when tab closes or server restarts
|
|
138
|
+
- **Not suitable for persistence**: Use databases for permanent storage
|
|
139
|
+
|
|
140
|
+
## References
|
|
141
|
+
|
|
142
|
+
- [st.session_state API](https://docs.streamlit.io/develop/api-reference/caching-and-state/st.session_state)
|
|
143
|
+
- [Session State concepts](https://docs.streamlit.io/develop/concepts/architecture/session-state)
|
|
144
|
+
- [Widget behavior](https://docs.streamlit.io/develop/concepts/architecture/widget-behavior)
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# Streamlit Dashboard App Templates
|
|
2
|
+
|
|
3
|
+
This directory contains ready-to-use dashboard templates for Streamlit. Each template demonstrates best practices for building data-driven dashboards with modern UI patterns.
|
|
4
|
+
|
|
5
|
+
## Available Templates
|
|
6
|
+
|
|
7
|
+
### Public Demo Templates
|
|
8
|
+
|
|
9
|
+
These templates are based on official Streamlit demo apps and work out of the box:
|
|
10
|
+
|
|
11
|
+
| Template | Description | Key Features |
|
|
12
|
+
|----------|-------------|--------------|
|
|
13
|
+
| **dashboard-seattle-weather** | Weather data exploration dashboard | `st.metric`, `st.pills`, `st.altair_chart`, year comparison |
|
|
14
|
+
| **dashboard-stock-peers** | Stock peer analysis and comparison | `st.multiselect`, normalized charts, peer average calculation |
|
|
15
|
+
| **dashboard-stock-peers-snowflake** | Same as above but using Snowflake | `st.connection("snowflake")`, synthetic stock data in SQL |
|
|
16
|
+
|
|
17
|
+
### Analytics Dashboard Templates
|
|
18
|
+
|
|
19
|
+
These templates demonstrate common dashboard patterns with synthetic data. Replace the data generation functions with your actual data sources:
|
|
20
|
+
|
|
21
|
+
| Template | Description | Key Features |
|
|
22
|
+
|----------|-------------|--------------|
|
|
23
|
+
| **dashboard-metrics** | Core metrics dashboard with KPIs | Chart/table toggle, `st.popover` filters, TIME_RANGES (1M/6M/1Y/QTD/YTD/All) |
|
|
24
|
+
| **dashboard-metrics-snowflake** | Same as above but using Snowflake | `st.connection("snowflake")`, SQL-based data generation |
|
|
25
|
+
| **dashboard-feature-usage** | API endpoint usage analytics | Segmented control, starter kits, normalization toggle, rolling averages |
|
|
26
|
+
| **dashboard-companies** | Company leaderboard with drill-down | Interactive dataframe, sparkline columns, growth scores |
|
|
27
|
+
| **dashboard-compute** | Resource consumption monitoring | `@st.fragment`, `st.popover` filters, TIME_RANGES, line/bar toggle |
|
|
28
|
+
| **dashboard-compute-snowflake** | Same as above but using Snowflake | `st.connection("snowflake")`, SQL-based data generation |
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### Run a Template Locally
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Navigate to a template directory
|
|
36
|
+
cd templates/apps/dashboard-metrics
|
|
37
|
+
|
|
38
|
+
# Install dependencies with uv
|
|
39
|
+
uv pip install -e .
|
|
40
|
+
|
|
41
|
+
# Run the app
|
|
42
|
+
uv run streamlit run streamlit_app.py
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Template Structure
|
|
46
|
+
|
|
47
|
+
Each template follows this structure:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
dashboard-{name}/
|
|
51
|
+
├── streamlit_app.py # Main application code
|
|
52
|
+
└── pyproject.toml # Dependencies and metadata
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Canonical Patterns
|
|
56
|
+
|
|
57
|
+
When creating new templates or adapting existing ones, follow these patterns for consistency.
|
|
58
|
+
|
|
59
|
+
### Page Configuration
|
|
60
|
+
|
|
61
|
+
Always set page config as the first Streamlit call, with `layout="wide"` and a Material icon:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
st.set_page_config(
|
|
65
|
+
page_title="My Dashboard",
|
|
66
|
+
page_icon=":material/monitoring:",
|
|
67
|
+
layout="wide",
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Constants
|
|
72
|
+
|
|
73
|
+
Use these standard constant names:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
TIME_RANGES = ["1M", "6M", "1Y", "QTD", "YTD", "All"]
|
|
77
|
+
CHART_HEIGHT = 300 # Standard chart height in pixels
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Time Range Filtering
|
|
81
|
+
|
|
82
|
+
All dashboard templates that support time filtering use the same `filter_by_time_range` function:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
def filter_by_time_range(df: pd.DataFrame, x_col: str, time_range: str) -> pd.DataFrame:
|
|
86
|
+
"""Filter dataframe by time range."""
|
|
87
|
+
if time_range == "All" or df.empty:
|
|
88
|
+
return df
|
|
89
|
+
|
|
90
|
+
df = df.copy()
|
|
91
|
+
df[x_col] = pd.to_datetime(df[x_col])
|
|
92
|
+
max_date = df[x_col].max()
|
|
93
|
+
|
|
94
|
+
if time_range == "1M":
|
|
95
|
+
min_date = max_date - timedelta(days=30)
|
|
96
|
+
elif time_range == "6M":
|
|
97
|
+
min_date = max_date - timedelta(days=180)
|
|
98
|
+
elif time_range == "1Y":
|
|
99
|
+
min_date = max_date - timedelta(days=365)
|
|
100
|
+
elif time_range == "QTD":
|
|
101
|
+
quarter_month = ((max_date.month - 1) // 3) * 3 + 1
|
|
102
|
+
min_date = pd.Timestamp(date(max_date.year, quarter_month, 1))
|
|
103
|
+
elif time_range == "YTD":
|
|
104
|
+
min_date = pd.Timestamp(date(max_date.year, 1, 1))
|
|
105
|
+
else:
|
|
106
|
+
return df
|
|
107
|
+
|
|
108
|
+
return df[df[x_col] >= min_date]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Popover Filters
|
|
112
|
+
|
|
113
|
+
Compact filter controls using `st.popover`:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
with st.popover("Filters", type="tertiary"):
|
|
117
|
+
line_options = st.pills("Lines", ["Daily", "7-day MA"], selection_mode="multi")
|
|
118
|
+
time_range = st.segmented_control("Time range", TIME_RANGES, default="All")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Page Header with Reset Button
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
def render_page_header(title: str):
|
|
125
|
+
"""Render page header with title and reset button."""
|
|
126
|
+
with st.container(
|
|
127
|
+
horizontal=True, horizontal_alignment="distribute", vertical_alignment="center"
|
|
128
|
+
):
|
|
129
|
+
st.markdown(title)
|
|
130
|
+
if st.button(":material/restart_alt: Reset", type="tertiary"):
|
|
131
|
+
st.session_state.clear()
|
|
132
|
+
st.rerun()
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Independent Widget Updates with @st.fragment
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
@st.fragment
|
|
139
|
+
def metric_card():
|
|
140
|
+
with st.container(border=True):
|
|
141
|
+
# This widget updates independently without full page rerun
|
|
142
|
+
...
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Snowflake Column Normalization
|
|
146
|
+
|
|
147
|
+
Snowflake returns uppercase column names. Always normalize after queries:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
df = conn.query(query)
|
|
151
|
+
df.columns = df.columns.str.lower()
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Snowflake Connection Error Handling
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
try:
|
|
158
|
+
get_snowflake_connection()
|
|
159
|
+
except Exception as e:
|
|
160
|
+
st.error(f"Failed to connect to Snowflake: {e}")
|
|
161
|
+
st.info(
|
|
162
|
+
"Make sure you have configured your Snowflake connection in "
|
|
163
|
+
"`.streamlit/secrets.toml` or via environment variables."
|
|
164
|
+
)
|
|
165
|
+
st.stop()
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Data Loading with Caching
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
@st.cache_data(ttl=3600)
|
|
172
|
+
def load_metric_data() -> pd.DataFrame:
|
|
173
|
+
"""Load metric data. Replace with your actual data source."""
|
|
174
|
+
# Replace this with:
|
|
175
|
+
# - Snowflake query via st.connection("snowflake")
|
|
176
|
+
# - API call
|
|
177
|
+
# - Database query
|
|
178
|
+
return generate_synthetic_data()
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Dependencies
|
|
182
|
+
|
|
183
|
+
All templates require Python >=3.11 and use:
|
|
184
|
+
- `snowflake-connector-python>=3.3.0` (required — `streamlit[snowflake]` silently skips this on Python 3.12+)
|
|
185
|
+
- `streamlit[snowflake]>=1.54.0`
|
|
186
|
+
- `altair>=5.5.0`
|
|
187
|
+
- `pandas>=2.2.3`
|
|
188
|
+
- `numpy>=1.26.0`
|
package/.agents/skills/developing-with-streamlit/templates/apps/dashboard-companies/pyproject.toml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "dashboard-companies"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "A company analytics dashboard with leaderboard, filtering, and drill-down dialogs"
|
|
5
|
+
requires-python = ">=3.11"
|
|
6
|
+
dependencies = [
|
|
7
|
+
"altair>=5.5.0",
|
|
8
|
+
"numpy>=1.26.0",
|
|
9
|
+
"pandas>=2.2.3",
|
|
10
|
+
"snowflake-connector-python>=3.3.0",
|
|
11
|
+
"streamlit[snowflake]>=1.54.0",
|
|
12
|
+
]
|