Navigating through dataframe records

Hi there,

I would like to create an app that navigates through the record of a dataframe. Basically, I would the first record of the dataframe to be displayed, then the user clicks a โ€œnextโ€ button and the second record is now displayed etc.

Is there already an existing component/element to do that?

I hope my question is clear. I just started using Streamlit :relaxed:
Thanks!

Hi @MrnRbn , Welcome to the Streamlit Community Forum.

would you like to navigate through each rows of the data frame ?
Hereโ€™s a code snippet below. Refer to Streamlit Session State demo apps

import streamlit as st
import pandas as pd  
# initialize list of lists
data = {'col1': [1, 2, 3, 4], 'col2': [300, 400, 500, 600]}  
# Create the pandas DataFrame
df = pd.DataFrame(data) 
# print dataframe.
st.dataframe(df)
# Using Session State for pagination
# from example - https://github.com/streamlit/release-demos/blob/0.84/0.84/demos/pagination.py
if "row" not in st.session_state:
    st.session_state.row = 0

def next_row():
    st.session_state.row += 1

def prev_row():
    st.session_state.row -= 1

col1, col2, _, _ = st.columns([0.1, 0.17, 0.1, 0.63])

if st.session_state.row < len(df.index)-1:
    col2.button(">", on_click=next_row)
else:
    col2.write("") 

if st.session_state.row > 0:
    col1.button("<", on_click=prev_row)
else:
    col1.write("") 

st.write(df.iloc[st.session_state.row])

streamlit-test-2021-12-01-12-12-88

Otherwise, you can also implement the component , Streamlit-AgGrid - an user-interactive table.
Hope this helps.

Best,
Avra

2 Likes

Exactly what I was looking for :raised_hands:
Thank you so much!

1 Like

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