Streamlit Toggle Switch

1.0.2 · deprecated · verified Thu Apr 16

streamlit-toggle-switch is a Streamlit custom component that provides a customizable toggle switch widget, offering options for color and placement. The current version is 1.0.2. The library has not seen updates since late 2022, and its functionality has largely been superseded by a native Streamlit widget.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `streamlit-toggle-switch` component and also includes the recommended native `st.toggle` widget for comparison.

import streamlit as st
from streamlit_toggle import st_toggle_switch

st.title('Custom Toggle Switch Demo')

# Example using the custom component
is_enabled = st_toggle_switch(
    label='Enable Feature X',
    key='feature_x_toggle',
    default_value=False,
    label_after=True,
    inactive_color='#D3D3D3',  # Optional
    active_color='#11567f',   # Optional
    track_color='#29B5E8'     # Optional
)

if is_enabled:
    st.write('Feature X is enabled!')
else:
    st.write('Feature X is disabled.')

st.subheader('Native Streamlit Toggle (Recommended)')

native_toggle_on = st.toggle('Activate native feature')
if native_toggle_on:
    st.write('Native feature activated!')

view raw JSON →