Is there a way to collapse/expand table rows?

Hello,

I am not looking for ready made code, I am just curios if the streamlit library has the capability to collape/expand some rows based on an identifier.

My data consists of multiple rows with entries that detail purchases of an item at different price points and dates. I want to see a “summarize” row that consists of a sum of all item quantities and an average or the purchase price - this row I can create through python or maybe streamlit could create it automatically. Once I have this row, if I click it I want to see all item purchases, then if I click it again I want to see just the summarize row.

My question is: is there such a capability built in streamlit and if it is can you please tell me what I should look into?

Thank you!

You would need to handle the logic yourself as there aren’t built-in summarizing features like that. If I were to make something as you describe I’d probably put together the following pieces:

  1. Use st.data_editor to display all the summary rows and include a boolean column for the user to check or uncheck to “Show details.”

  2. Based on the output of st.data_editor, I’d gather the additional data into one or more st.dataframe displays below it.

I’m not deeply familiar with streamlit_aggrid which is an add-on for Streamlit. I think it has some ability to do a summary row, but I’m not sure if it will serve your use case. Still, you might check that out.

1 Like

I was just looking into streamlit_aggrid, thank you for your suggestions.

I think, at this time, the st.data_editor way is simpler, for me.

1 Like

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