Hello,
I have a list of dynamic number of buttons to be put in columns. (If I have 10 buttons, I will have 10 columns).
It seems that the button can take a width bigger than the width of the column it self. How can I fix that?
Ideally it would be better to increase the height of the button instead of its width.
(I changed the string in each column by the number of characters for security reasons).
nb_buttons = 10
cols_info_c = st.columns(nb_buttons)
for col in cols_info_c:
col = st.empty()
for index, button_name in enumerate(list_button_names):
cols_info_c[index].button(
button_name,
on_click=some_function,
args=(button_name,),
)
Hi @Rima , it looks like you want to dynamically put buttons into columns.
What you could do is set the page config to be the wide layout and thus u get more space to work with:
st.set_page_config(layout="wide")
However, if that’s not enough, maybe you can do a few rows of x amount columns?
something like:
#function which split the list into two halves
def splitlist(inputlist,n):
first_half=inputlist[:n]
sec_half=inputlist[n:]
return first_half,sec_half
nb_buttons = 10
cols_info_c_0 = st.columns(nb_buttons / 2)
cols_info_c_1 = st.columns(nb_buttons / 2 + (nb_buttons%2)) # add 1 if odd
for col in cols_info_c_0:
col = st.empty()
for col in cols_info_c_1:
col = st.empty()
first_half, sec_half = splitlist(list_button_names, len(list_button_names))
for index, button_name in enumerate(first_half):
cols_info_c0[index].button(
button_name,
on_click=some_function,
args=(button_name,),
)
for index, button_name in enumerate(sec_half):
cols_info_c1[index].button(
button_name,
on_click=some_function,
args=(button_name,),
)
Hello @willhuang , thank you for your answer. I implemented a similar method to yours (instead of having dynamic number of columns according to the number of buttons) I specificied a maximum number of columns in each “line”. But the problem persists.
To clarify, the problem is a UI bug, since the button depends on the resolution of the page (and the screen). If the page is too small, buttons will overlap, if the page is maximized, the buttons will be perfect and far from each other.
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.