HI,
I have begun using streamlit and I like it, itโs simple and effective.
My first app was an image labeler (10 images, drop downs to select the labels and a save button) and I had to use a little hack to save when pressing the save button by calling the save function and triggering a RerunException to load new images. It works fine but it feels a little bit hacky.
Which leads me to the following question, does streamlit have the ambition to become a full fledged frontend library with event listeners and layouts? Something like Kivy for web apps.
Layouts example would be BoxLayout, FloatLayout, GridLayout
EventListeners examples would be on_click, on_hover, on_mouse_down, on_mouse_up, on_key_press etc
I would be absolutely delighted if it did as all pythonistas know too well that writing frontend code with web tech is not easy compared to a regular UI library (kivy, pyQT etc).
Please advise
1 Like
Another question is state management / stateful apps. This is what I am currently using:
import os
import pickle
import streamlit as st
class State:
def __init__(self, path='state.pickle', default_state_class=dict):
self.path = path
self.default_state_class = default_state_class
def load(self):
if os.path.exists(self.path):
with open(self.path, 'rb') as inf:
self.state = pickle.load(inf)
else:
self.state = self.default_state_class()
def get_state(self):
return self.state
def save(self):
with open(self.path, 'wb') as outf:
pickle.dump(self.state, outf)
def rerun():
raise st.script_runner.RerunException(st.script_request_queue.RerunData(None))
def app():
store = State()
store.load()
name = store.get_state().get('name', None)
if name:
st.text(f'Hello {name}')
else:
st.text(f'Please enter your name')
name_input = st.text_input('your name')
name = name_input
if name != '':
store.get_state()['name'] = name
store.save()
next_page = st.button('Next page')
if next_page:
rerun()
if __name__ == "__main__":
app()