Streamlit component that allows you to do manage local storage
Project description
Streamlit local storage
This repo is to help streamlt users manage data in a browser's local storage.
pip install streamlit-local-storage
from streamlit_local_storage import LocalStorage
localS = LocalStorage()
store an array to local storage
localStorageArray = [
{"key":"Games", "toStore":[{"name":"Basically does this work"}]},
{"key":"Winners", "toStore":[{"name":"Basically does this work Though"}]}
]
localS.setList(localStorageArray)
store individual items from local storage
itemKey = "camera"
itemValue = "Tarah"
localS.set(itemKey, itemValue)
get list of items from local storage
data_ = [{"key":"camera"}, {"key":"JamesLook"}]
saved_ = localS.getList(data_)
st.write(saved_)
get all items saved on local storage
saved_individual = localS.getAll()
st.write(saved_individual)
when getting local storage items with streamlit widgets
st.subheader("Method 1")
localS = LocalStorage()
if "button_to_get_storage_val" not in st.session_state:
st.session_state["button_to_get_storage_val"] = False
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_local_storage_v")
st.form_submit_button("Submit")
if st.session_state["get_local_storage_v"] != "":
val_ = localS.getItem(st.session_state["get_local_storage_v"], key="test_get_item")
st.session_state["get_val"] = val_
st.write(st.session_state["get_val"])
st.subheader("Method 2")
localS = LocalStorage()
if "button_to_get_storage_val_2" not in st.session_state:
st.session_state["button_to_get_storage_val_2"] = False
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]:
localS.getItem(st.session_state["get_local_storage_v_2"], key="test_get_item_2")
with st.form("get_data_2"):
st.text_input("key", key="get_local_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"]
st.write(st.session_state["get_val_2"])
delete item and item list from local storage
saved_individual = localS.deleteList([{"key": "ThomasKing"}, {"key":"Somethingelse"}])
localS.deleteItem('Tony')
delete all
localS.deleteAll()
get all
localS.getAll()
Remember to refresh browser if it does not pop up instantly.
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
streamlit-local-storage-0.0.5.tar.gz
(443.1 kB
view hashes)
Built Distribution
Close
Hashes for streamlit-local-storage-0.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 826998b74943725176eec4d53d37c0a109bfa8ebe07c68d15ef5e1fbeee00b07 |
|
MD5 | d7b79624902be86ea19ad0e1ca4b7fce |
|
BLAKE2b-256 | 3cab9e6395948fb828ef3aef086e6fcd367e36df4cfbadb99b7e3e096abc58cd |
Close
Hashes for streamlit_local_storage-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b051df80801fb0d45e03513efd94da5930d8041d6661bb410cd0323072e7cabd |
|
MD5 | a6766ad409235a266fe930df6ea86475 |
|
BLAKE2b-256 | e76bd1a826f0bde02d72b8a662bb58fac62e587a4e88dbaaabcc61bb2f03179b |