Streamlit Card

1.0.2 · active · verified Wed Apr 15

Streamlit Card is a custom component that allows developers to easily create interactive and customizable UI cards within their Streamlit applications. It provides options for displaying titles, text, images, and handling clicks, enhancing the visual appeal and interactivity of Streamlit dashboards. The library is currently at version 1.0.2 and receives active maintenance updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create two types of cards: one that redirects to a URL upon click, and another that triggers an internal Streamlit callback function. It also shows basic styling customization.

import streamlit as st
from streamlit_card import card

st.set_page_config(layout='wide')

st.title("My Streamlit Cards Demo")

# Example 1: Basic Clickable Card with URL
has_clicked_github = card(
    title="Visit GitHub",
    text="Explore the source code of streamlit-card.",
    image="https://placekitten.com/200/300",
    url="https://github.com/gamcoh/st-card",
    styles={
        "card": {
            "width": "300px",
            "height": "200px",
            "border-radius": "10px",
            "box-shadow": "0 0 10px rgba(0,0,0,0.2)"
        }
    }
)

if has_clicked_github:
    st.write("Redirecting to GitHub...")

# Example 2: Card with internal callback for interaction
def handle_card_click():
    st.session_state['card_message'] = 'Card was clicked! You can perform actions here.'

if 'card_message' not in st.session_state:
    st.session_state['card_message'] = 'Click the card below!'

has_clicked_callback = card(
    title="Interactive Card",
    text="Click me to trigger an action within the app.",
    image="https://placebear.com/200/300",
    on_click=handle_card_click,
    styles={
        "card": {
            "width": "300px",
            "height": "200px",
            "border-radius": "10px",
            "background-color": "#f0f2f6",
            "box-shadow": "0 0 10px rgba(0,0,0,0.1)"
        }
    }
)

st.write(st.session_state['card_message'])

view raw JSON →