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.1.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.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: streamlit_grid-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 d829ca021de876e31bb6e22a4823bcb367986e5ced4d91eb3ece91f1e45d34a9
MD5 9813784fa8197bbafd06fb3ebd91745d
BLAKE2b-256 01b600eebe43efe002e303b7425940e7aeab80524a78abad9623b3ac088f2e6c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: streamlit_grid-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a2f837a2cb6332965873b21d7d679173879b5997be353171a1d93bca4e476e4
MD5 be43e053bceaf74326961afbd732f27c
BLAKE2b-256 73855703d5bd2a85e9eb8b068877bcd46315d52d3088ca5c8bc1c01510d7f283

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