Skip to main content

A Streamlit custom component for displaying SVG animations with interactive play, pause, and restart controls

Project description

Streamlit SVG View

A Streamlit custom component for displaying SVG animations with interactive play, pause, and restart controls.

Features

  • Interactive Controls - Play, pause, and restart SVG animations with hover overlay controls
  • Customizable Colors - Set custom colors for control buttons to match your app's theme
  • Responsive Design - Works seamlessly across different screen sizes
  • Cross-browser Compatible - Supports all modern browsers with graceful fallbacks
  • Lightweight - Minimal dependencies and optimized performance
  • Easy Integration - Simple API that works with any animated SVG

Installation

pip install streamlit-svg-view

Quick Start

import streamlit as st
from streamlit_svg_view import svg_view

# Your animated SVG content
svg_content = '''
<svg width="200" height="200" viewBox="0 0 200 200">
    <circle cx="100" cy="100" r="50" fill="blue">
        <animate attributeName="r" values="50;80;50" dur="2s" repeatCount="indefinite"/>
        <animate attributeName="fill" values="blue;red;blue" dur="2s" repeatCount="indefinite"/>
    </circle>
</svg>
'''

# Display with controls
result = svg_view(svg_content, width=250, height=250)
st.write("Animation state:", result)

API Reference

svg_view(svg_content, width=None, height=None, play_color=None, pause_color=None, restart_color=None, key=None)

Parameters

  • svg_content (str): The SVG content as a string
  • width (int, optional): Component width in pixels (default: 400)
  • height (int, optional): Component height in pixels (default: 300)
  • play_color (str, optional): Color for the play button (CSS format)
  • pause_color (str, optional): Color for the pause button (CSS format)
  • restart_color (str, optional): Color for the restart button (CSS format)
  • key (str, optional): Unique key for the component instance

Returns

dict: Component state containing:

  • is_playing (bool): Whether animations are currently playing
  • action (str): Last user action ('play', 'pause', 'restart', or 'state_change')

Examples

Basic Usage

import streamlit as st
from streamlit_svg_view import svg_view

# Simple pulsing circle
svg = '''
<svg width="100" height="100" viewBox="0 0 100 100">
    <circle cx="50" cy="50" r="20" fill="blue">
        <animate attributeName="r" values="20;30;20" dur="1s" repeatCount="indefinite"/>
    </circle>
</svg>
'''

svg_view(svg)

Custom Colors

# Match your app's color scheme
svg_view(
    svg_content,
    play_color="#ff6b6b",      # Coral red
    pause_color="#4ecdc4",     # Turquoise  
    restart_color="#45b7d1",   # Sky blue
    width=300,
    height=200
)

License

This project is licensed under the MIT License - see the LICENSE file for details.

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_svg_view-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

streamlit_svg_view-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: streamlit_svg_view-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for streamlit_svg_view-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bef9780ecdc47a69fd9f45c8f5aff2b16d5685ff18845d683924b922c9f25b6e
MD5 acbbeaec81be7dcef8939678b1b33b62
BLAKE2b-256 ae1dd86d72f71cf2925d89c893cf1181cf363ac048793fe768beb3e66a0b66d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for streamlit_svg_view-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 74ed2760bad5240dd11090599e2e074d16b502fda96b88a8ba3891dc4cfbe59a
MD5 f5545ad8a46a6c10230e92b41d63e051
BLAKE2b-256 3df9631d7933a413a04a98823511caee7115aca5bcea1808954058a2af1077fe

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