St.download on multiple tabs

I am running these following codes and am having some few errors:

  • Anytime I click the download button the entire app reloads
  • The tables are not populated in the remaining tabs.

Please do you have ideas on how to fix it?

import streamlit as st

import numpy as np

import pandas as pd

from st_aggrid import GridOptionsBuilder, AgGrid, GridUpdateMode, DataReturnMode, JsCode

from streamlit.components.v1 import html

st.set_page_config(layout=“wide”)

lst = [‘Accra’, ‘Kumasi’, ‘Tamale’,‘Abuja’, ‘Delhi’, ‘Tokyo’]

A = pd.DataFrame(np.random.randint(0,800,size=(800, 4)), columns=list(‘ABCD’))

B = pd.DataFrame(np.random.randint(0,800,size=(800, 4)), columns=list(‘ABCD’))

C = pd.DataFrame(np.random.randint(0,800,size=(800, 4)), columns=list(‘ABCD’))

D = pd.DataFrame(np.random.randint(0,800,size=(800, 4)), columns=list(‘ABCD’))

E = pd.DataFrame(np.random.randint(0,800,size=(800, 4)), columns=list(‘ABCD’))

F = pd.DataFrame(np.random.randint(0,800,size=(800, 4)), columns=list(‘ABCD’))

nam = [A,B,C,D,E,F ]

man = [F,E,D,C,D,A]

tabs= st.tabs(lst)

for i, tab in enumerate(tabs):

with tab:

col1, col2 = st.columns(2)

with col1:

st.subheader(‘First Data’)

st.dataframe (nam[i])

st.download_button(label=‘Download’, data=nam[i].to_csv(), mime=‘text/csv’, key = 1)

with col2:

st.subheader(‘Second Data’)

st.dataframe (man[i])

st.download_button(label=‘Download’, data=man[i].to_csv(), mime=‘text/csv’, key = 2)

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