Thanks I have read it. Yet I still don’t understand what is container good for. Can you show an example for something which cannot be done without a container?
Ofcourse, an UI can be designed without specifically the st.container() widget, if the workarounds are known.
However, there are times, when the container widget comes very handy , for instances (Here’s the reference to the doc),
import streamlit as st
import numpy as np
st.header("Demo")
cont = st.container()
_plotType = st.selectbox("Plot Type", ['Line','Bar'])
if _plotType == 'Line':
cont.header("Line Plot")
cont.line_chart(np.random.randn(50, 3),use_container_width = True)
if _plotType == 'Bar':
cont.header("Bar Plot")
cont.bar_chart(np.random.randn(50, 3),use_container_width = True)
Probably you are already aware, that the Streamlit App, runs line by line in your code. In this case, let’s consider, you plan to plot in the very top of your app, just below the header. So, you leave a empty container, and populate it based on your user’s choice. If container layout isn’t used, the plot appears after the user’s choice .
I hope this makes sense. (Perhaps a better example would make more sense , let me know) .
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.