streamlit icon indicating copy to clipboard operation
streamlit copied to clipboard

Toggle/Switch: Slider with two values

Open StefanBrand opened this issue 4 years ago • 20 comments
trafficstars

Ported from https://discuss.streamlit.io/t/toggle-switch-slider-with-two-values/13086?u=stefanbrand


Using CSS and deleting/reordering some HTML in my browser's developer tools, I hacked this from a select_slider:

image

python st.select_slider("Displayed values:", ["Normalized", "Absolute"])

Would be cool to have something built-in that looks similar to this (regarding the display of labels, not the design):
image

What do you think?


Edit: I found this related topic, but it also does not have the labels to the left/right of the toggle: https://discuss.streamlit.io/t/toggle-switch-wip/3967/4?u=stefanbrand


Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.

If you'd like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.

StefanBrand avatar Jun 07 '21 11:06 StefanBrand

Thank you for sharing your slider ideas! Our mission is to make Streamlit the best way to build data apps, and your thoughts help us focus our roadmap where people feel the most pain. We're going to get this in front of our product team to see how we can best integrate this with our future plans.

We can't integrate every feature into the mainline codebase, but alternatively there are lots of interesting ways to extend Streamlit for your use cases via our Custom Components framework. You can read the docs about components here. If you can't use Custom Components, don't forget, Streamlit is really just Python, so the possibilities are endless! 🙂

We'll get back to you if we are able to prioritize this work!

jroes avatar Jun 07 '21 14:06 jroes

Any progress? voting this up because it is something a UI needs quite often and it is much prettier than a selectbox

breinbaas avatar Mar 31 '22 13:03 breinbaas

@StefanBrand and @breinbaas: We are looking into implementing a toggle soon but I'm not really decided whether we should have a toggle as here or a toggle button (i.e. just a button with two values), or possibly both. Can you share what exactly you want the toggle for? Also happy about sketches / screenshots!

jrieke avatar Jun 28 '22 17:06 jrieke

A check box always implies on/off or activated/deactivated. My use case is detailed in the first post: normalized/absolute, something which is not conveyed by a check box with only one label.

StefanBrand avatar Jun 29 '22 10:06 StefanBrand

but I'm not really decided whether we should have a toggle as here or a toggle button (i.e. just a button with two values)

I know that's an important question, so have you decided on that @jrieke.

btw there are many good UI libraries which implement both. it's solved and there are valid use cases.

nihiluis avatar Aug 26 '22 15:08 nihiluis

Would be a great one to have, both toggles switch and custom binary buttons

spencervoorend avatar Nov 01 '22 20:11 spencervoorend

One use-case for which I wanted this switch button is to have two modes on the page namely Dev Mode and Demo Mode. Usually I would like the app to dump some extra info in the Dev Mode and Hide them in the Demo Mode

Presently I do have such requirement and I am searching how to implement this functionality in the Streamlit APP.

I would also like to change the theme of the app programmatically, using an api to set theme, so that both the modes have different themes. I do not know how to achieve this currently :(

dhirajsuvarna avatar Nov 09 '22 18:11 dhirajsuvarna

There are a few components for this functionality now: Streamlit Toggle Switch and Toggle switch (WIP)

carolinefrasca avatar Nov 10 '22 01:11 carolinefrasca

@jrieke Does #7012 close this?

sfc-gh-dmatthews avatar Aug 09 '23 21:08 sfc-gh-dmatthews

No, let's leave this issue open.

We added st.toggle in the latest release, which allows to add an on/off toggle (similar to a checkbox). But this issue specifically calls for having a toggle that lets you toggle between two different values. We might do this in the future.

jrieke avatar Sep 07 '23 21:09 jrieke

Yes, I was just looking for this feature today - please implement it

mkleinbort-ic avatar Nov 21 '23 17:11 mkleinbort-ic

we would also love this feature !

cgagel-PA avatar Dec 07 '23 23:12 cgagel-PA

Me too!

yashasbvn avatar Feb 02 '24 08:02 yashasbvn

Please implement this. It will be great to have it.

Gboyehigh avatar Feb 22 '24 20:02 Gboyehigh

I would love this feature too!

sorozco-graticule avatar Apr 03 '24 14:04 sorozco-graticule

That would be useful

LombardiNicola avatar Apr 18 '24 16:04 LombardiNicola

This is what I am looking for it too

packydarn avatar Jul 24 '24 02:07 packydarn

me to

TheDjaangoo avatar Aug 07 '24 20:08 TheDjaangoo

Not a direct solution but a decent alternative that I currently use is the radio button with Horizontal = True

st.radio(
      "Choose Option",
      ["Toggle On", "Toggle Off"],
      horizontal = True
      )

cgage1 avatar Aug 08 '24 18:08 cgage1

I realized today if we add segmented controls/buttons, this would also be a pretty good solution for toggles with two values. E.g. something like this:

CleanShot 2024-08-24 at 04 09 03

sfc-gh-jrieke avatar Aug 24 '24 02:08 sfc-gh-jrieke