Created
May 4, 2023 10:10
-
-
Save mikekenneth/63181af0fc6c0fc4b412b5b9bc45c681 to your computer and use it in GitHub Desktop.
Streamlit month picker using selectbox and radio.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
from calendar import month_abbr | |
from datetime import datetime | |
with st.expander('Report month'): | |
this_year = datetime.now().year | |
this_month = datetime.now().month | |
report_year = st.selectbox("", range(this_year, this_year - 2, -1)) | |
month_abbr = month_abbr[1:] | |
report_month_str = st.radio("", month_abbr, index=this_month - 1, horizontal=True) | |
report_month = month_abbr.index(report_month_str) + 1 | |
# Result | |
st.text(f'{report_year} {report_month_str}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment