Hey, I wanted to ask what’s the recommended coding pattern for persistent streamlit settings.
Currently, I am using shelve to pickle/dill python objects that contain a collection of my settings.
Of course, I could also write the values directly to a DB. Though, saving snapshots of singleton objects allows me to version instances of different settings.
I just wonder if am thinking too complicated here. Maybe there’s a way to store the whole session as is, and reload it later.
I do it like this:
class Setting: X = 10 def options(self): self.X = st.number_input("my value", value=self.X) config = get_last_setting() config.options() if st.button("Save new Setting"): save_setting(config)
save_setting would be database functions that retrieve a shelve object of
Setting. It somehow works conveniently to have the class variable as default and once we call options, it becomes an instance bound variable, which can be persisted. But it all feels hacky and complicated.
A much more convenient approach would be to just snapshot the current session object so that all UI Elements entries are persisted.
if st.button("Load last session"): load_last_session() #This number input will be automatically set to the value which we used in the last session config.X = st.number_input("My Value") if st.button("Save session"): save_session()
Do you think there could be any way to implement that?