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!