Beta_columns for date_input and time_input on sidebar

Hello community,

I am trying to set a date_input and time_input in the same row with beta_columns on the sidebar. The idea is to have date and time side-by-side. Does anyone know how to do it?

I tried this but It does not work:

layout = st.sidebar.beta_columns([2, 1])
with layout[0]: 
    start_date = st.sidebar.date_input('Desde:', NOW_DATE)
 
with layout[-1]: 
    start_hour = st.sidebar.time_input('Hora:', NOW_DATE)

Hi @gabriel87,

Good question! As layout[0] and layout[-1] are columns in the sidebar, elements to be added in those columns should be declared via st.element() when using the with notation or else call the methods directly on the returned object. E.g. layout[0].element().

In your case, simply omit sidebar when you’re creating the date and time widgets like so:


import streamlit as st

layout = st.sidebar.beta_columns([2, 1])

with layout[0]: 
    start_date = st.date_input('Date:') # omit "sidebar"
 
with layout[-1]: 
    start_hour = st.time_input('Time:') # omit "sidebar"

Here’s what the output looked like on my end:

Let me know if this is what you had in mind :slightly_smiling_face:

Happy Streamlit-ing! :balloon:
Snehan

wow that looks perfect to me … thanks a lot

1 Like