Save User Input into a DataFrame and Access Later


I want to create an App which shows a images to a customer based on its user id and takes inputs from them basis some filters.

Is there a way to save all the inputs into a Dataframe and access that later ? There could be multiple users entering at the same time.


Hi @Nikhil_Agarwal, welcome to Streamlit!

I’m not sure I completely understand what you’re asking, but yes - you can certainly save the results of inputs to a Dataframe (or any other structure) using Streamlit.

import streamlit as st
import pandas as pd

def get_data():
    return []

user_id = st.text_input("User ID")
foo = st.slider("foo", 0, 100)
bar = st.slider("bar", 0, 100)

if st.button("Add row"):
    get_data().append({"UserID": user_id, "foo": foo, "bar": bar})


This example appends entries to a cached list, and then converts that list to a dataframe on demand. If you’ll have multiple users editing this simultaneously, you probably want to append to a file on disk every time the “Add Row” button is pressed, rather than just appending to an in-memory file.