So i have been using columns for my layouts, but i just realised i could add with notations to the columns. I am wondering, why is ‘with’ important? How is it different from using just columns?
Steps to reproduce
Code snippet:
add code here
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
Explain what you expect to happen when you run the code above.
Actual behavior:
Explain the undesired behavior or error you see when you run the code above.
If you’re seeing an error message, share the full contents of the error message here.
Debug info
Streamlit version: (get it with $ streamlit version)
Python version: (get it with $ python --version)
Using Conda? PipEnv? PyEnv? Pex?
OS version:
Browser version:
Requirements file
Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.
Links
Link to your GitHub repo:
Link to your deployed app:
Additional information
If needed, add any other context about the problem here.
import streamlit as st
import pandas as pd
col1, col2, col3 = st.columns(3)
col1.write('# Column 1')
col2.write('# Column 2')
col3.write('# Column 3')
# When you want to add to a column:
# Option 1: Use a method on the column object (most of the same things you can
# get using st.<method> in general)
col1.write('Line 2')
col1.dataframe(pd.DataFrame({'A':[1,2,3],'B':['a','b','c']}))
col1.code('import streamlit as st\n' \
'\n' \
'st.write(\'hello\')')
# Option 2: Use *with* and then indent all the things you are adding as you would
# with any conditional or loop. This allows you to skip putting the column name
# in front of each line of code. It's personal taste and context that will determine
# which is stylistically preferable.
with col2:
st.write('Say I want to do a lot of things in column 2 all at once. Maybe ' \
'I\'ll just use `with` and indent those several lines of code.')
st.slider('Choose',1,5,3)
st.caption('Meow')
# You can mix and match using a method on the column option and using the with
# syntax.
with col3:
st.write('Hi!')
col3.write('Hi, again!')
# And of course you can add on to any column at any time, so you can go back and
# append to col1 at the end if you want.
col1.write('P.S. One more thing')
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.