Muni1
September 21, 2024, 9:21pm
1
I am looking for a way to create toggle (or check box) buttons with customized icon.
My use case involves situations where checkboxes or toggles, along with text, take up too much space. In contrast, buttons with icons can be arranged more compactly, saving space.
Since these buttons represent checkbox/toggles logic, they need to
have a on and a off state
change the state upon each click
present different icons for different state
It is possible to get something similar to this today, but it doesn’t look quite as nice as the example you gave:
import streamlit as st
from streamlit_extras.stateful_button import button
columns = st.columns(10)
icons = ["🍎", "🍌", "🍇", "🍓", "🍒", "🍑", "🥭", "🍍", "🥥", "🥝"]
selected_icons = []
for index, column in enumerate(columns):
with column:
if button(icons[index], key=f"button_{index}"):
selected_icons.append(icons[index])
st.write("Selected icons:", selected_icons)
The good news is, there is official support for this coming soon!
You can see it on the Roadmap: https://roadmap.streamlit.app/
And here is a sneak peek: x.com
1 Like
I added a feature request to GitHub for image parsing on buttons if you want to vote and comment there. As @blackary mentioned, there is an improvement coming for the “group of toggles” part of your question. This GitHub issue is for the “custom image” part of your question:
opened 02:58PM - 24 Sep 24 UTC
type:enhancement
feature:markdown
area:widgets
### Checklist
- [X] I have searched the [existing issues](https://github.com/… streamlit/streamlit/issues) for similar feature requests.
- [X] I added a descriptive title and summary to this issue.
### Summary
Labels (such as for buttons) have limited markdown supported. Although, Streamlit has added icon support in markdown, we don't yet have custom icons or images.
Markdown supports images through ``. This is not parsed in labels. If it was, people could use custom svg files to put images on buttons or make their own icons (both as small, inline icons, or as a larger image.
### Why?
This would allow custom images on buttons. See this forum post (the button group part is being handled elsewhere): https://discuss.streamlit.io/t/how-to-create-toggle-buttons-with-customized-icon/81773/2
### How?
Include the image directive in markdown parsing for labels.
```python
import streamlit as st
st.button("") # Not parsed in label arguments
st.markdown("")
```
### Additional Context
_No response_
2 Likes
system
Closed
March 23, 2025, 3:03pm
4
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.