Skip to main content

Streamlit component that allows you to create interactive grid layouts in your Streamlit apps.

Project description

Streamlit Grid

Streamlit Grid is a custom Streamlit component that allows you to create interactive grid layouts in your Streamlit apps. It supports row and column spanning, custom colors, and dynamic layouts.

Features

  • 🟦 Grid-based layout for Streamlit
  • 🔢 Supports row and column spanning
  • 🎨 Customizable cell colors
  • âš¡ Easy integration into Streamlit apps

Installation

pip install streamlit-grid

Usage

import streamlit as st
from streamlit_grid import streamlit_grid, GridItem

st.subheader("Streamlit Grid Example")

grid = [
    [GridItem("C", col_span=2, background_color="red", text_color="white"), GridItem("/"), GridItem("*")],
    [GridItem("7"), GridItem("8"), GridItem("9"), GridItem("-")],
    [GridItem("4"), GridItem("5"), GridItem("6"), GridItem("+", row_span=2)],
    [GridItem("1"), GridItem("2"), GridItem("3")],
    [GridItem("0"), GridItem("00"), GridItem("."), GridItem("=", background_color="#2B90DE", text_color="white")],
]

selected_value = streamlit_grid(
    grid_layout=grid, 
    columns=4, 
    gap=5, 
    cell_height=20,
    background_color="#ccc",
)

st.write(f"#### You clicked: {selected_value}")

Parameters

Parameter Type Description
grid_layout List[List[GridItem]] A 2D list representing the grid layout.
columns int (Optional) Number of columns in the grid.
gap int (Optional) Gap between grid items (in pixels).
cell_height int (Optional) Height of each grid cell.
background_color str (Optional) Background color of the grid container.
key str (Optional) Unique key for the component state.

GridItem Options

Attribute Type Description
label str Text inside the cell.
background_color str (Optional) Background color of the cell.
text_color str (Optional) Text color inside the cell.
row_span int (Optional) Number of rows the cell spans.
col_span int (Optional) Number of columns the cell spans.

Example Output

The following example creates a calculator-style grid:

Example Grid


Contributing

We welcome contributions! To contribute:

  1. Ensure you have the necessary dependencies installed:

  2. Clone the repository:

    git clone https://github.com/syedahoorainali/streamlit-grid-component.git
    
  3. Set up the Python environment:

    cd streamlit-grid-component
    python3 -m venv venv  # Create virtual environment
    . venv/bin/activate   # Activate virtual environment
    pip install streamlit  # Install Streamlit
    pip install -e .  # Install package in editable mode
    
  4. Run the Streamlit app:

    streamlit run streamlit_grid/example.py
    
  5. Set up and run the frontend component:

    cd streamlit_grid/frontend
    npm install  # Install dependencies
    npm run start  # Start Webpack dev server
    
  6. Make changes to the component:

    • Modify the frontend code in streamlit_grid/frontend/src/StreamlitGrid.tsx
    • Modify the backend Python code in streamlit_grid/__init__.py
  7. Build the frontend:

    npm run build
    
  8. Submit a pull request 🚀


License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_grid-0.1.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_grid-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_grid-0.1.0.tar.gz.

File metadata

  • Download URL: streamlit_grid-0.1.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for streamlit_grid-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cb05ccefc5390fdaa09bcba9c77ca14f27696902c97cf4dab36007c920fcbfff
MD5 031cf850624ac55ea838bde91e47c3ba
BLAKE2b-256 98a26f3ea5cb935932c685b6434433d5a5c49381369f4d63dead3e1c9f91aecf

See more details on using hashes here.

File details

Details for the file streamlit_grid-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: streamlit_grid-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for streamlit_grid-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a802d89151412326ff5f1aa63a460069af2d32775183af943bc008ac73b9dc4d
MD5 569fbf97baea151814e5b8c5e336d60e
BLAKE2b-256 71e6457b00845d99bbe6a467f767337acfe3db660f0fcad7578aff1f1c02d1ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page