New Component: `st_btn_select` - Selectbox alternative with buttons

Logo

Homepage Demo
Streamlit Button Select Component


Sometimes you want a user to make a selection, but you only have a few options.
Using an st.selectbox component works, but wouldn’t it be easier to simply have a few buttons in a row ?
Well, this custom component allows just that !

Installation

pip install st_btn_select

Usage

Creating a Button Selection is really easy.

from st_btn_select import st_btn_select

selection = st_btn_select(('option 1', 'option 2', 'option 3'))
st.write('selection')

You can also use this component as a small top navigation bar.

from st_btn_select import st_btn_select

page = st_btn_select(
  # The different pages
  ('home', 'about', 'docs', 'playground'),
  # Enable navbar
  nav=True,
  # You can pass a formatting function. Here we capitalize the options
  format_func=lambda name: name.capitalize(),
)

# Display the right things according to the page
if page == 'home':
  st.write('HOMEPAGE')

NOTE
There can only be one navbar per page, as they will be displayed on top of each other.

The navbar buttons do not set any URL hashes, and thus the different pages are not bookmarkable, nor can you use the browser history.

Documentation

Check out this streamlit app for the documentation, as well as a demo.
Open in Streamlit

Yeah that’s very nice!

Do you mind adding your component to the Component Tracker so we don’t lose sight of it :slight_smile: ?

Thanks again, have a nice day!
Fanilo :balloon:

I would like to, but since I just created this account I do not have a trust level 1 yet…
Not sure how to reach that either :sweat_smile:

EDIT: I just reached trust level 1 and thus added my component to the wiki! :+1:

Congratulations on reaching TL1 :smiley: