I am wondering how to defer showing the st.data_editor (e.g. not at the point in the script when the st.data_editor function is called). The case I have is something like below. There are a large number of countries (for example) and their dataframes may be heterogeneous, and quite long. For that reason it is not practical or aesthetically appealing to show them all at once. Is there a way to accomplish what I want to do? Thanks!
input_country_lane = st.selectbox("Select country", input_countries, None)
country_df = {}
for country in input_countries:
country_lanes[country] = st.data_editor(country_specific_data[country], key=f"{country}_df")
if input_country_lane != None :
country_lanes[input_country_lane]
You can rearrange elements and render them out of order using containers, but the st.data_editor command (by definition) creates the dataframe editor on the front end. The Streamlit rendering commands are all like that. The actual frontend object and state are abstracted away so you as the developer only declare the points where/when you want to display something on the front end.
If you don’t want to show all the data editors at once, you’d have to programmatically handle that in your script to only call the st.data_editor for those ones that you do want to show. e.g. Insert a selectbox or multiselect for the user to choose from a list of countries, then only display the selected data editors.
Alternatively, if different sizing is an issue you can work with height parameters to standardize the result a little bit.
I just thought of a solution which works for me and seems to play nicely with how these things are intended to be used.
input_country_lane = st.selectbox("Select country", input_countries, None)
country_df = {}
for country in input_countries:
country_lanes[country] = country_specific_data[country] # more complex than this in reality
if input_country_lane != None :
country_lanes[input_country_lane] = st.data_editor(country_lanes[input_country_lane])
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.