Streamlit component that allows you to do manage local storage
Project description
Streamlit sessionBrowser storage
This repo is to help streamlt users manage data in a browser's sessionBrowser storage.
Built on the use-sessionBrowser-storage-state
that allows for real time updates especially important when sessionBrowser storage item is deleted.
for more details:
https://www.npmjs.com/package/use-session-storage-state
pip install streamlit-session-browser-storage
import SessionStorage
sessionBrowserS = SessionStorage()
store items to sessionBrowser storage
itemKey = "camera"
itemValue = "Tarah"
sessionBrowserS.setItem(itemKey, itemValue)
get item from sessionBrowser storage
itemKey = "Taylor Swift"
sessionBrowser_storage_item = sessionBrowserS.getItem(itemKey)
get all items saved on sessionBrowser storage
saved_individual = sessionBrowserS.getAll()
st.write(saved_individual)
delete all
sessionBrowserS.deleteAll()
when getting sessionBrowser storage items with streamlit widgets
st.subheader("Method 1")
def sessionBrowserStorageManager():
return SessionStorage()
sessionBrowserS = sessionBrowserStorageManager()
if "get_val" not in st.session_state:
st.session_state["get_val"] = None
with st.form("get_data"):
st.text_input("key", key="get_sessionBrowser_storage_v")
st.form_submit_button("Submit")
if st.session_state["get_sessionBrowser_storage_v"] != "":
val_ = sessionBrowserS.getItem(st.session_state["get_sessionBrowser_storage_v"], key="test_get_item")
st.session_state["get_val"] = val_
st.write(st.session_state["get_val"])
### When using callbacks for get item, can use the below example. But it wont reveal data unless app has rendered twice. But callback can be work without a hitch generally (based on my tests).
st.subheader("Method 2 - using callback. Does not load instantly especially for get storage")
def sessionBrowserStorageManager():
return SessionStorage()
sessionBrowserS = sessionBrowserStorageManager()
if "get_val_2" not in st.session_state:
st.session_state["get_val_2"] = None
if "st_col_test" not in st.session_state:
st.session_state["st_col_test"] = None
def change_state_2():
with st.session_state["st_col_test"][0]: # call method from below form
sessionBrowserS.getItem(st.session_state["get_sessionBrowser_storage_v_2"], key="test_get_item_2") # initialise/run method and value will be stored in `session_state`
with st.form("get_data_2"):
st.text_input("key", key="get_sessionBrowser_storage_v_2")
st.form_submit_button("Submit", on_click=change_state_2)
st.session_state["st_col_test"] = st.columns(1) #to make sure rendering happens below form (or other streamlit element. Else the re-rendering of component upon re-running of up will be run at the top of the streamlit component (form here) which creates nasty ui experience.)
if "test_get_item_2" in st.session_state and st.session_state["test_get_item_2"] != None:
st.session_state["get_val_2"] = st.session_state["test_get_item_2"] # if sessionBrowser storage method is initialised, get the stored value and use it throughout the app.
st.write(st.session_state["get_val_2"])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for streamlit-browser-session-storage-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f49a0b5e3de688f8e64ca4647b769f2e3c77e1b36505fbb89e825d588a7d560 |
|
MD5 | 4a6ffb5ccfbb3362e39a796adc0059fe |
|
BLAKE2b-256 | fbd7ecdb8ee33790c6a5c15ae7a526ce4d8abe528b8af177ac376350101e39d6 |
Close
Hashes for streamlit_browser_session_storage-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae75891d0c711a6f5875b2edbe81f7731ba54405b3df1d15d85a5b6c69ac02dc |
|
MD5 | 1454b94189dbe0ebc947ac358f6c994e |
|
BLAKE2b-256 | ae2476dc175df7f9bd188c5973f20c5d9a14209917c04861072c9e567d24b6c3 |