I’d like to add a feature to my streamlit app where a list ends with a “Show more” button, and pressing the button queries for more data, and puts the “Show more” button at the end of the extended list. Exactly like how google scholar implements it: https://scholar.google.com/citations?user=JicYPdAAAAAJ&hl=en&oi=ao
Using the https://gist.github.com/tvst/036da038ab3e999a64497f42de966a92 SessionState.py class, I came up with something nice that’s quite similar:
import random import time import streamlit as st import SessionState @st.cache def long_calculation(i): time.sleep(1) return 1000 * i + random.randrange(100) def main(): session_state = SessionState.get(length=5) if st.button("Show more"): session_state.length += 5 for i in range(1, session_state.length + 1): st.write("item %d: %d" % (i, long_calculation(i))) main()
The only difference between this and my imagined ideal solution is that here the “Show more” button is at the beginning, not at the end where it should be. Unfortunately this is extremely bad UX for long lists, and I’m stuck here. Is there a way to fix this issue, either along these lines, or starting from scratch?