Hi, is there a way to centre a widget (eg. st.button) horizontally within a column?
Thanks in advance.
Hi, is there a way to centre a widget (eg. st.button) horizontally within a column?
Thanks in advance.
Thanks for your question.
Would you be able to provide a quick mock-up of what you are after?
Many thanks,
Charly
Hi @Charly_Wargnier, thanks for replying.
I am in the process of creating a calendar application - ref pix.
I am unable to horizontally centre the widgets (st.buttons with emoji) within each of the 7 weekday columns.
Additionally, I set the sidebar length to 440px. Because of this, it does not completely close. Is that a bug / limitation?
Cheers
Thanks for sending this @Shawn_Pereira
Would it be possible for you to share the code? I’ll try to make this work
As for the sidebar, its length can’t be modified currently.
Many thanks,
Charly
For the sake of brevity, I have added the stripped down code for the 1st week of Dec-2021.
import streamlit as st
from datetime import datetime as dt
import calendar as clndr
cyr = 2021
cmnt = 12
myclndr = clndr.monthcalendar(cyr, cmnt)
wk1 = myclndr[0]
html_str_a = “
”
html_str_b = “
cols = st.columns(7)
for vday in wk1:
if vday > 0:
cols[vday].markdown(html_str_a + str(vday).zfill(2) + html_str_b, unsafe_allow_html=True)
cols[vday].button(“”, key=f"DY{vday}")
else:
cols[vday].write(" ")
Thanks in advance
Cheers
Thanks, @Shawn_Pereira. We’ll have a look
Meanwhile, not sure if you’ve seen, but @andfanilo has created an excellent video tutorial (another one!) on how to create a pseudo grid layout using Streamlit columns, you may find it interesting.
Best,
Charly
Thanks @Charly_Wargnier , I saw the video.
I look forward to the future releases of Streamlit for more possibilities with the same ease of use.
Streamlit is really awesome and is now my go-to tool for every web programming project.
God bless.
Not sure I totally understood, but with your code snippet are you talking
Instead of
?
You can cheat an answer through the CSS hack, if you know your way around CSS:
import streamlit as st
from datetime import datetime as dt
import calendar as clndr
cyr = 2021
cmnt = 12
myclndr = clndr.monthcalendar(cyr, cmnt)
wk1 = myclndr[0]
html_str_a = ""
html_str_b = ""
cols = st.columns(7)
for vday in wk1:
if vday > 0:
cols[vday].markdown(
html_str_a + str(vday).zfill(2) + html_str_b, unsafe_allow_html=True
)
cols[vday].button(":spiral_calendar:", key=f"DY{vday}")
else:
cols[vday].write(" ")
st.markdown(
"""
<style>
div[data-testid="stVerticalBlock"] div[data-testid="stMarkdownContainer"] p {
background-color:red;
text-align: center;
}
</style>
""",
unsafe_allow_html=True
)
I tried summarizing here: CSS hacks for the dumb? - #3 by andfanilo
And @dataprofessor made a video about it How to apply custom CSS styles in Streamlit apps - YouTube
It’s hard to deal with and maintain but possible. I don’t think there is a Github issue on that though (we do have the horizontal align issue: Vertical alignment for columns · Issue #3052 · streamlit/streamlit (github.com) so feel free to create an issue to track it.
Best,
Fanilo
Hi @andfanilo , thanks for responding.
No, my issue is not with CSS. In fact, with my earlier copy-paste, I see that the values of html_str_a and html_str_b are blank. I tried re-pasting the code, but these variables still turn out blank!
I have got my desired effect as you can see with the pix; however, I cant seem to be able to horizontally centre the st.buttons right below the day numbers.
Thanks
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
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.
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.
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.
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.