Socvest / streamlit-pagination

Mui pagination component to segment data by numbered pages
MIT License
32 stars 5 forks source link

need to tab twice to change pages using st.columns #1

Open doyikim1 opened 9 months ago

doyikim1 commented 9 months ago

Hi, I've applied pagination in st.columns. it appears fine but clicking once doesn't change pages. it needs to tab twice. could you give some help please?

def display_page_content(sorted_files, start_index, end_index):
    global shared_state

    cols = st.columns([2, 1, 1, 1, 1])
    for col, field in zip(cols, table_header):
        col.write("**" + field + "**")

    for filename, file_path in sorted_files[start_index:end_index]:
        if filename in st.session_state['analysis_futures']:
            future = st.session_state['analysis_futures'][filename]
            if future.done():
                st.session_state['analysis_status'][filename] = 'Analysis Complete'
                st.session_state['analysis_results'][filename] = future.result()
                shared_state = st.session_state

        cols = st.columns([2, 1, 1, 1, 1])
        cols[0].write(filename)
        cols[1].write(st.session_state['upload_status'][filename])
        cols[2].write(st.session_state['analysis_status'][filename])

        with cols[3]:
            reanalyze_button = st.button(label='Reanalyze', key=f'reanalyze-{filename}')
            if reanalyze_button:
                reanalyze_file(filename)
                cols[4].empty()

        with cols[4]:
            if st.session_state['analysis_status'][filename] == 'Analysis Complete':
                download_results(filename)

def main():

    if st.session_state.page == 'Upload page':
        st.title("Upload your video")
        uploaded_file = st.file_uploader("Choose a file", type=["mp4"])
        if uploaded_file is not None:
            handle_file(uploaded_file)

    elif st.session_state.page == 'Collections':
        st.title("results")
        sorted_files = sorted(st.session_state['uploaded_files'].items(), key=lambda item: os.path.getmtime(item[1]), reverse=True)

        total_files = len(sorted_files)
        current_page = st.session_state['current_page']
        start_index = (current_page - 1) * PAGE_SIZE
        end_index = start_index + PAGE_SIZE

        display_page_content(sorted_files, start_index, end_index)

        layout = {'color': "primary", 'style': {'margin-top': '10px', 'display': 'flex','justify-content': 'center'}}
        selected_page = pagination_component(math.ceil(total_files / PAGE_SIZE) + 1, layout=layout) + 1
        print(selected_page)
        st.session_state['current_page'] = selected_page

if __name__ == "__main__":
    main()
Socvest commented 8 months ago

Hey, so I will be honest with you I don't really maintain this any longer. But Try the pagination component here. Much easier to use.