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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file streamlit_svg_view-0.2.0.tar.gz.
File metadata
- Download URL: streamlit_svg_view-0.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d27dec0f8480bd101f8b2a667d99bfc43f05f5d2f05454836483d0058ae9523
|
|
| MD5 |
174b592fb62d1916133968d2ea8af634
|
|
| BLAKE2b-256 |
8ca71767ad3dc5bfb680677f2ab16d8336a9ab39beb8bcb38c0aaa98c7e26d1d
|
File details
Details for the file streamlit_svg_view-0.2.0-py3-none-any.whl.
File metadata
- Download URL: streamlit_svg_view-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9945c6b42bd3f5cfbc29924927a895c75257625078dd43d815e3c688845ca1fa
|
|
| MD5 |
122dc9d532558d2faafd4c37084a5ec3
|
|
| BLAKE2b-256 |
9c0d40d2c517c61e465e8b9068c2332e9f105eb31cac67a4df504f88ccc3c341
|