Maintaining the display of a dataframe

Hello everybody !
I have a problem, I use buttons to make some computing and displaying dataframes, I press the first button to display my first dataframe and when I press the second button, my second dataframe is shown but my first disappears. I want to maintain the display of my first dataframe (and all those before)…
A code example :

import streamlit as st
import pandas as pd

st.subheader("Test")

df_first = pd.DataFrame({"col1": [1, 2, 3, 1, 2, 3], "col2": [4, 5, 6, 4, 5, 6]})
df_second = pd.DataFrame({"col1": [100, 200, 300], "col2": ["www.google.com", "www.facebook.com", "www.youtube.com"]})

button_first = st.button("Display first")
if button_first :
    st.write(df_first)

button_second = st.button("Display second")
if button_second:
    st.write(df_second) 

Anybody know how to proceed ?

@nvk - display the tables using button on_click callbacks. A button’s True state is only valid at the time it is clicked, then it immediately returns to False when Streamlit reruns. Or you can use st.checkbox instead.

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