OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Column layout inside submit form streamlit

  • Thread starter Thread starter Quinten
  • Start date Start date
Q

Quinten

Guest
I would like to have two selectbox elements side by side in a st.form using a st.columns layout. Unfortunately the select boxes are out of the form. Here is some reproducible code:

Code:
import streamlit as st

st.header("Selectbox side by side in form")

col1, col2 = st.columns(2)

with st.form('Form1'):
    col1.selectbox("Select track",  ["track 1", "track 2"])
    col2.selectbox("Select track 2",  ["track 1", "track 2"])
    st.slider("Select your race finish position", 1, 12, key="number")
    st.form_submit_button('Submit your race')

Output:

enter image description here

As you can see the select boxes are out of the form which is not what I want. If you use only one selectbox it is of course inside the form, but I would like to have two select boxes side by side. So I was wondering if anyone how to use a column layout inside a form in streamlit?
<p>I would like to have two <code>selectbox</code> elements side by side in a <a href="https://docs.streamlit.io/develop/api-reference/execution-flow/st.form" rel="nofollow noreferrer"><code>st.form</code></a> using a <code>st.columns</code> layout. Unfortunately the select boxes are out of the form. Here is some reproducible code:</p>
<pre><code>import streamlit as st

st.header("Selectbox side by side in form")

col1, col2 = st.columns(2)

with st.form('Form1'):
col1.selectbox("Select track", ["track 1", "track 2"])
col2.selectbox("Select track 2", ["track 1", "track 2"])
st.slider("Select your race finish position", 1, 12, key="number")
st.form_submit_button('Submit your race')
</code></pre>
<p>Output:</p>
<p><a href="https://i.sstatic.net/XIPht0Oc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/XIPht0Oc.png" alt="enter image description here" /></a></p>
<p>As you can see the select boxes are out of the form which is not what I want. If you use only one selectbox it is of course inside the form, but I would like to have two select boxes side by side. So I was wondering if anyone how to use a column layout inside a form in streamlit?</p>
 

Latest posts

Top