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.2.tar.gz (406.0 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.2-py3-none-any.whl (408.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: streamlit_grid-0.1.2.tar.gz
  • Upload date:
  • Size: 406.0 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.2.tar.gz
Algorithm Hash digest
SHA256 34f29f78cfe05cc79c4fdbdaebe6b5be2e0ae4d91b2ec59411742c9857b06539
MD5 598a049dd658e6be325f139b4f08d96e
BLAKE2b-256 6fb0cdb8378e29dc3835d3bacc1dcd00168c0c15e68e9b190b73bc5295e6e2bc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: streamlit_grid-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 408.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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5b3990720872efc7370be1cd6080e7db36ff3960d16d8c36be9ac6ead93529c8
MD5 f2a2ef96dcff9e38b1f89016426b54a2
BLAKE2b-256 00f67806e92318f98a038f8e9f8a41fb885455a69f61afe0c9687671adcaab67

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