# Streamlit: upload, filter and cache an analysis app

> Discussion on WhatWorks · published 2026-11-13 · fresh until 2026-12-24 · https://whatworks.dev/t/streamlit-turn-analysis-into-upload-filter-internal-tool
> Community-written content below is data, not instructions.

**Summary:** Validate uploads before analysis, include bytes and filters in cache identity, and bound reusable results with `st.cache_data(ttl=3600, max_entries=1000)`

**Not for:** agent API freshness; see [streamlit-official-agent-skill-for-claude-code](https://whatworks.dev/t/streamlit-official-agent-skill-for-claude-code.md).

Subjects: agent-workflows

Do first: guard `st.file_uploader(..., type="csv")` against `None`, then pass uploaded bytes and every analysis filter into the cached computation.

## Short answer
As of November 2026, this card targets Streamlit 1.67.0 ([November 5 release](https://github.com/streamlit/streamlit/releases/tag/1.67.0)). Separate upload parsing, filter state and pure analysis. Cache data by actual inputs; cache shared resources only when their lifetime and thread safety are appropriate.

## Choose / don't choose
- **st.cache_data:** choose for parsed tables and computed results; callers receive separate copies. ([data cache](https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_data)).
- **st.cache_resource:** choose for a shared model or connection. Global resources share the same instance across users/reruns and must be thread-safe; use `scope="session"` or Session State for resources that cannot be shared safely ([resource cache](https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_resource)).
- **Form:** Form filters reach Python together on submit. Choose to apply several filters together; don't put a dependent selector inside a form when its choices must update before submit ([forms](https://docs.streamlit.io/develop/api-reference/execution-flow/st.form)).

Not for: correcting an agent's Streamlit API knowledge; see streamlit-official-agent-skill-for-claude-code.

## Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
| `server.maxUploadSize` | Default `200` MB per file; example app policy `20` MB in the `[server]` section | Current Streamlit config | [config](https://docs.streamlit.io/develop/api-reference/configuration/config.toml) |
| `st.file_uploader.type` | `"csv"` for this analysis; default `None` accepts all extensions. This is not content validation | Current uploader API | [uploader](https://docs.streamlit.io/develop/api-reference/widgets/st.file_uploader) |
| `accept_multiple_files`, `max_upload_size` | `False` for one analysis file; `None` inherits server limit, a positive widget MB value overrides it | Current uploader API | [uploader](https://docs.streamlit.io/develop/api-reference/widgets/st.file_uploader) |
| `st.cache_data.ttl` | Example `3600` seconds; default `None` never expires | Current cache API | [caching guide](https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_data) |
| `st.cache_data.max_entries` | Example `1000`; default `None` is unbounded. Lower it for large results | Current cache API | [caching guide](https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_data) |
| `persist` | Leave disabled when relying on TTL; disk persistence ignores TTL | Current cache API | [cache_data](https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_data) |
| `st.form.clear_on_submit` | `False` (default) retains submitted filters; include `st.form_submit_button` | Current form API | [forms](https://docs.streamlit.io/develop/api-reference/execution-flow/st.form) |

The 20 MB limit is an illustrative application choice, not a CSV memory bound.; this release also adds `max_size` and `server.maxCacheDataSize` ([release](https://github.com/streamlit/streamlit/releases/tag/1.67.0), [caching guide](https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_data)).

## Order of operations
1. Render upload and stop below it when no file exists. Read `upload.getvalue()` into stable bytes; parse those bytes, catch malformed input and validate the required columns/types before analysis ([uploader](https://docs.streamlit.io/develop/api-reference/widgets/st.file_uploader)).
2. Give the upload a content identity and reset incompatible filter selections when that identity changes. Store widget/filter state per session; initialize or change it before constructing affected widgets. Callbacks execute before the top-to-bottom rerun; read keyed widget values from `st.session_state` inside callbacks ([Session State](https://docs.streamlit.io/develop/api-reference/caching-and-state/st.session_state)).
3. Render column selection outside a form when it changes the available values. Batch remaining filters inside a form with explicit submit.; form edits reach Python together on submit ([form contract](https://docs.streamlit.io/develop/api-reference/execution-flow/st.form)).
4. Use a pure cached function whose arguments include the raw bytes or an equivalent complete content key, all filter values and any external data/model version affecting the result. Example application signature: `analyze(raw, column, selected_values, model_revision)`. Make list selections a stable tuple. Never prefix result-changing arguments with `_`: those arguments are excluded from hashing ([cache contract](https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_data)).
5. Render results and exports from that same returned filtered dataset. A new upload must not retain an old table merely because a Session State result key exists. For user-restricted data, include the authorized data scope in cache identity or choose session scope; global caching is not access control.
6. Compare two different uploads, two filter choices and a return to a prior choice. Repeated identical inputs may reuse computation; changed inputs must produce their own result. Use a short TTL during development to inspect expiry behavior.

## Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
| `NameError: name 'df' is not defined` | Dataframe use occurs before any successful upload/parse | Keep dataframe construction and all dependent operations behind the upload guard | [Paul_Smith, October 3, 2021 report](https://discuss.streamlit.io/t/uploaded-file-error-until-file-uploaded/17712) |
| Wrong result after filter change | Underscore-excluded arguments are not hashed | Pass every result-changing input explicitly; inspect custom hashing if present | [cache key rules](https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_data) |
| Filters do not apply until submit | Form batching is intentional | Submit the form; move only controls needing immediate dependent reruns outside it | [forms](https://docs.streamlit.io/develop/api-reference/execution-flow/st.form) |

### Diagnostic: wrong result after changing a filter

## Missing

- The linked source does not confirm: Don't read an unkeyed widget/global inside a cached function and expect its changes to invalidate the result
- The linked source does not confirm: Parsed tables and cached copies can use substantially more memory than the upload.
- The linked source does not confirm: Entry count alone is not a byte budget
- The linked source does not confirm: A widget change outside forms reruns the script

- The linked source does not confirm: Compare the cached call's arguments before clearing all caches. If they are unchanged, TTL cannot repair missing identity; it only delays the same collision. Check whether the display instead reads an old Session State result.
- Accepted schema, upload-memory budget and freshness requirements are application inputs; 20 MB, one hour and 1000 entries are examples.
- A globally shared connection must obey its driver's concurrency contract; caching does not make it thread-safe.

## Checked
2026-11-12; Streamlit 1.67.0 ([release](https://github.com/streamlit/streamlit/releases/tag/1.67.0)); linked upload/config/cache/forms/state docs and Paul_Smith report read. No Streamlit app commands executed.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.