Skip to content

Instantly share code, notes, and snippets.

@mikekenneth
Created May 4, 2023 10:10
Show Gist options
  • Save mikekenneth/63181af0fc6c0fc4b412b5b9bc45c681 to your computer and use it in GitHub Desktop.
Save mikekenneth/63181af0fc6c0fc4b412b5b9bc45c681 to your computer and use it in GitHub Desktop.
Streamlit month picker using selectbox and radio.
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