A Streamlit component for a selectable grid
Project description
Streamlit Selectable Grid
A Streamlit component that displays a selectable grid of cells with support for headers, row indices, and custom styling options.
Installation
pip install st-selectable-grid
Usage
import streamlit as st
from st_selectable_grid import st_selectable_grid
# Create a grid with header and index
cells = [
[
{"label": "A1", "cell_color": "#f0f8ff", "tooltip": "Cell A1", "mark": True},
{"label": "<b>A2</b>", "cell_color": "#e6e6fa", "html": True},
{"label": "A3", "cell_color": "#f5f5dc"}
],
[
{"label": "B1", "cell_color": "#f0ffff"},
{"label": "<span style='color:red'>B2</span>", "cell_color": "#f5f5f5", "html": True},
{"label": "B3", "cell_color": "#fffaf0"}
],
[
{"label": "C1", "cell_color": "#fff0f5"},
{"label": "C2", "cell_color": "#f0f0f0"},
{"label": "<i>C3</i>", "cell_color": "#fffff0", "html": True}
]
]
header = [
{"label": "Column 1", "cell_color": "#e0e0e0", "mark": True},
{"label": "Column 2", "cell_color": "#e0e0e0"},
{"label": "Column 3", "cell_color": "#e0e0e0"}
]
index = ["Row 1", "Row 2", "Row 3"]
selection = st_selectable_grid(
cells=cells,
header=header,
index=index,
aspect_ratio=1.0,
allow_secondary_selection=True,
allow_header_selection=True,
height=300,
grid_position="center",
resize=True,
mark_color="#2196F3",
primary_selection_color="#2196F3",
secondary_selection_color="#FF9800",
key="grid1"
)
if selection:
if "primary" in selection:
st.write("Primary selection (left click):", selection["primary"])
if "secondary" in selection:
st.write("Secondary selection (right click):", selection["secondary"])
Features
- Interactive grid with selectable cells
- Support for headers and row indices
- Customizable cell colors and aspect ratio
- Primary (left-click) and secondary (right-click) selections
- Tooltips on hover
- Cell marking with indicator dots
- Responsive design with positioning options
- Fixed or flexible sizing options
- HTML formatting support for cell content
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
cells |
List[List[dict or str]] | Required | 2D array of dictionaries or strings to be displayed in the grid. Dictionary keys: label, cell_color, tooltip, mark, html. |
header |
List[dict or str] or None | None | Optional 1D array for column headers. Same format as cells. |
index |
List[dict or str] or None | None | Optional 1D array for row indices. Same format as cells. |
aspect_ratio |
float | 1.0 | Controls the aspect ratio (height/width) of cells. |
allow_secondary_selection |
bool | False | If True, allows right-click to select a secondary cell. |
allow_header_selection |
bool | False | If True, allows header cells to be selected. |
height |
int or None | None | Optional height constraint in pixels. If None, grid sizes automatically based on width. |
resize |
bool | True | If True, grid resizes to fill available space. If False, maintains size based on content. |
grid_position |
str | 'center' | Horizontal alignment of the grid. Options: 'left', 'center', 'right'. Not applied if resize = True. |
mark_color |
str | '#2196F3' | Color for marker dots that appear on cells with mark=True. |
primary_selection_color |
str | '#2196F3' | Color for the primary (left-click) selection highlight. |
secondary_selection_color |
str | '#FF9800' | Color for the secondary (right-click) selection highlight. |
allow_copy_contents |
bool | False | If True, allows users to select and copy text within cells. If False, cells are clickable for selection but text cannot be highlighted. |
key |
str or None | None | Unique identifier for the component. |
Cell Dictionary Format
Each cell can be either a string (which becomes the label) or a dictionary with these keys:
label(str): The text to display in the cellcell_color(str): Background color in CSS format (e.g., "#f0f8ff" or "red")tooltip(str): Text to display when hovering over the cellmark(bool): If True, shows a marker dot in the top-right corner of the cellhtml(bool): If True, renders the label content as HTML, allowing formatting tags
HTML Formatting Example
You can use HTML tags in cell labels when the html flag is set to True:
cells = [
[
{"label": "Normal Text"},
{"label": "<b>Bold Text</b>", "html": True},
{"label": "<span style='color:red'>Red Text</span>", "html": True}
],
[
{"label": "<i>Italic</i>", "html": True},
{"label": "<b>Bold</b> and <i>italic</i>", "html": True},
{"label": "<u>Underlined</u>", "html": True}
]
]
Security Note: Use caution when setting html=True with untrusted content, as this could introduce security vulnerabilities.
Return Value
{
"primary": {"x": col_index, "y": row_index}, # For left-click selection
"secondary": {"x": col_index, "y": row_index} # For right-click selection (if enabled)
}
Secondary selection is only available after a primary selection has been made.
How to run in development mode
-
Clone the repository:
git clone https://github.com/hoggatt/st-selectable-grid.git cd st-selectable-grid
-
Create and activate a virtual environment (optional but recommended):
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install dependencies for both Python and frontend:
pip install -e . cd st_selectable_grid/frontend npm install
-
Run the frontend in development mode:
cd st_selectable_grid/frontend npm start
-
In a separate terminal, run the Streamlit app:
streamlit run st_selectable_grid/example.py
This will start the React development server for the component and connect it to your Streamlit app, allowing you to see changes in real-time as you modify the component code.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file st_selectable_grid-0.7.0.tar.gz.
File metadata
- Download URL: st_selectable_grid-0.7.0.tar.gz
- Upload date:
- Size: 427.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b22a5f061942c5c4225a0d3cde49dd8aab3f2d236ede686b8ed903981bf9d32
|
|
| MD5 |
e86d4336d87f49e7d064faebe0b66971
|
|
| BLAKE2b-256 |
3f5328af05695e620c4ecb5bda7564b2f134947092a1da37f64d1ecb5f6e7255
|
Provenance
The following attestation bundles were made for st_selectable_grid-0.7.0.tar.gz:
Publisher:
release.yml on hoggatt/st-selectable-grid
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
st_selectable_grid-0.7.0.tar.gz -
Subject digest:
5b22a5f061942c5c4225a0d3cde49dd8aab3f2d236ede686b8ed903981bf9d32 - Sigstore transparency entry: 705526905
- Sigstore integration time:
-
Permalink:
hoggatt/st-selectable-grid@8a1e62f5e6bf829708696ea9e34e3a935792f144 -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/hoggatt
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8a1e62f5e6bf829708696ea9e34e3a935792f144 -
Trigger Event:
push
-
Statement type:
File details
Details for the file st_selectable_grid-0.7.0-py3-none-any.whl.
File metadata
- Download URL: st_selectable_grid-0.7.0-py3-none-any.whl
- Upload date:
- Size: 430.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6493d44472261bed69b1ca53741c9b95846e11f6a508767e7849f5c1301726be
|
|
| MD5 |
bdb921782622adddd5876faabe02a8f7
|
|
| BLAKE2b-256 |
4c8e6f8e032cfcf9dc28de957f3c6b9bbb0996a76b3cb80ff000797b6e11399a
|
Provenance
The following attestation bundles were made for st_selectable_grid-0.7.0-py3-none-any.whl:
Publisher:
release.yml on hoggatt/st-selectable-grid
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
st_selectable_grid-0.7.0-py3-none-any.whl -
Subject digest:
6493d44472261bed69b1ca53741c9b95846e11f6a508767e7849f5c1301726be - Sigstore transparency entry: 705526907
- Sigstore integration time:
-
Permalink:
hoggatt/st-selectable-grid@8a1e62f5e6bf829708696ea9e34e3a935792f144 -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/hoggatt
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8a1e62f5e6bf829708696ea9e34e3a935792f144 -
Trigger Event:
push
-
Statement type: