How jrieke/streamlit-image-select works
Project type and purpose
• This is not a standalone full‐stack web app but a Streamlit “custom component” library. It provides a Python API (image_select) that under the hood spins up a small React/TypeScript front end to render a gallery of images and capture the user’s selection. A demo Streamlit app shows how to integrate and test it.
File structure
• Top level:
• pyproject.toml, README.md, license, demo directory
• Python package streamlit_image_select/
• Inside streamlit_image_select/:
• __init__.py – entry point, sets _RELEASE
• frontend/ – React app (package.json, src/, public/)
• Demo: a minimal Streamlit app (demo/streamlit_app.py) with its own requirements.txt
• Build & configuration files: poetry, npm scripts, .env, .prettierrc
README for additional insights
• The component follows the pattern of Streamlit’s [component template](): Python side defines the API, and the JS side runs in an isolated iframe on port 3001 (dev) or as a built bundle.
• Development workflow: start frontend dev server → run Streamlit with _RELEASE = False → see hot reload of both sides.
a. Main components
1. Streamlit “Demo App” (Python script)
2. Streamlit Server (Python runtime + Tornado web server)
3. streamlit-image-select Python package
4. Custom Component Bridge (the JSON‐RPC channel over HTTP/websocket between Python and JS)
5. React/TypeScript Frontend (served from local dev server or built bundle)
6. Browser (iframe host)
7. Optional External Services (PyPI for distribution)
b. Relationships and interactions
• The user opens the Demo App in their browser → Streamlit Server renders the page.
• When image_select() is called, Streamlit negotiates with the Custom Component Bridge to load the React frontend into an iframe.
• The frontend fetches image URLs, renders them, and listens for clicks.
• On selection, the frontend calls back via the component RPC into Python → Python returns the selected index or URL to the Streamlit app.
• For development, an npm start server on port 3001 serves the frontend; in production, a static bundle is used.
c. Architectural patterns and design principles
• Plugin‐style extension: clean separation of host app (Streamlit) and component code (frontend + Python wrapper).
• Client‐server split: Python (server) ↔ JavaScript (client) with a messaging bridge.
• Standard build pipeline: npm scripts for build/dev, Poetry for packaging.
d. Key technologies & libraries
• Python 3.x, Streamlit
• React + TypeScript, npm, webpack (under the hood)
• Poetry (dependency management)
• Streamlit component protocol (iframe + RPC)