MrnRbn
November 30, 2021, 9:51pm
1
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
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])
Otherwise, you can also implement the component , Streamlit-AgGrid - an user-interactive table.
Hope this helps.
Best,
Avra
3 Likes
MrnRbn
December 2, 2021, 1:16am
3
Exactly what I was looking for
Thank you so much!
1 Like
system
Closed
December 2, 2022, 1:17am
4
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.