Here is a quick component I wrote today. It is a very simple Toggle Switch component using React/Material-UI. Here is a quick snippet of it.
Install:
pip install streamlit-toggle-switch
Usage
import streamlit as st
import streamlit_toggle as tog
tog.st_toggle_switch(label="Label",
key="Key1",
default_value=False,
label_after = False,
inactive_color = '#D3D3D3',
active_color="#11567f",
track_color="#29B5E8"
)
Very useful and nice component.
Not sure, if its only me but font seems to be not matching with default theme.
Is it also in roadmap to have flip values on change.
I liked the toggle switch. I wish to get the text in line with the switch (centrally aligned) currently it’s a bit offset. I also want to make it a bit small. Can you please give me pointers on where to make changes?
Thanks.
Hi @CarlosSerrano , Thank you for this component. It looks great!
I am trying to use this in my streamlit application but am running into the function object has no attribute 'st_toggle_switch' error. Any ideas on how can I resolve it?
import streamlit as st
import streamlit_toggle as tog
tog.st_toggle_switch(label="Label",
key="Key1",
default_value=False,
label_after = False,
inactive_color = '#D3D3D3',
active_color="#11567f",
track_color="#29B5E8"
)
Thanks for the suggestion, @PabloCaSan. However, I am trying to add it to my sidebar. When I try to add st.sidebar.st_toggle_switch, it doesn’t work.
@Arushi_Agarwal This might might work. The label_after parameter can control the left and right anchoring (its getting renamed on v2) Please try this and let me know.
As far as I understand doing callbacks on custom components is not possible but I will check. Do you mind creating an issue on the github page for the component for tracking?
Hi @CarlosSerrano Thanks for trying. This is a great solution but it didn’t work for my case so I used simple radio buttons instead. But will give it a try again!
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.