col1_repl, col2_repl = st.columns(2)
col1,col2 = col1_repl.columns(2)
with col1_repl:
with st.form(key='my_form_non_empty'):
st_input = st.number_input if is_numeric_dtype(df[columns]) else st.text_input
with col1:
# do something
with col2:
this display the below error :
StreamlitAPIException: Columns may not be nested inside other columns.
Traceback:
File “f:\AIenv\streamlit\app2.py”, line 1332, in
main()
File “f:\AIenv\streamlit\app2.py”, line 682, in main
col1,col2 = col1_repl.columns(2)
Currently, you can’t create columns inside columns, that’s what the error message is saying.
If you want to create a big column next to 2 smaller columns then you can create unevenly sized columns from the first call like so:
col1,col2,col3 = st.columns([2,1,1])
This will make col1 twice the size of col2 and col3, effectively being the exact same visually as if you created 2 columns that you then split one in half.
No what i want is to create col1 that handle a form where inside the form i have subcol1subcol2 Col2 have a form with 1 text input and button.
All of this because i want to create a form that allow user to change the values of a field in dataframe
But i had the problem when the user need to replace the NAN values.
Because of that i tried to create this layout nested layout.
So is there another way to being able to replace the selected values and NAN values in the same form this will be very good for me.
I also want the nested columns to design a monitor with multiple panes which contains columns of sub-elements. The solution here did not really solve the issue of nested column layout. Appreciated if anyone knows how to achieve that. Thanks.
I’ve not found a real workaround but you can kind of solve it by using custom HTML elements and st.markdown() to replicate columns for simple elements.
Here is another hack: Nested Columns work fine in most cases. Just uncomment the error in the streamlit code (file PYTHON_PATH\lib\site-packages\streamlit\delta_generator.py line 557ff)
If someone stumbles upon this thread, from version 1.18.0, you can have one level of nested columns in the main area of the app! Check the changelog and the st.columns documentation for details.
import streamlit as st
## Define layout and containers
HEIGHT = 400
cols = st.columns(2)
with cols[0]:
left_panel = st.container(height=HEIGHT + 15, border=True)
with cols[1]:
upper_right_panel = st.container(height=HEIGHT//2, border=True)
lower_right_panel = st.container(height=HEIGHT//2, border=True)
## Add contents
with left_panel:
"## Left panel"
"A bunch of text " * 100
with upper_right_panel:
"## Upper right panel"
"A bunch of text " * 100
with lower_right_panel:
"## Lower panel"
"A bunch of text " * 100