How to prevent `st.data_editor` from being displayed when created?

Hi all,

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.

1 Like

Thank you! I am new to using st.data_editor.

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])
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.