StreamlitAPIException : Values for st.button, st.download_button, st.file_uploader, st.data_editor, st.chat_input, and st.form cannot be set using st.session_state.
with st.sidebar.form(key=‘device_s’):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
is here proper way around? I have few objects which have user defined values, which should be remembered. values should be visualized if user switch between objects. I thinked “st.form” good way. but now it look like dead end
import streamlit as st
from loguru import logger
from streamlit import session_state as ss
def connect():
ss.list_device_s = ["CCT10 - JETI_PE60"]
class Device:
def __init__(self, device_id,
exp_ms: float = 100.):
self.device_id: str = device_id
self.exp_ms: float = exp_ms
def select_settings() -> bool:
st.write(f"ss.list_device_s {ss.list_device_s}")
device_id = st.sidebar.selectbox("Select Device:", ss.list_device_s)
if device_id not in ss:
logger.info(f"Device ID: {device_id}")
ss[device_id] = Device(device_id=device_id)
st.warning(f"device_id: {device_id}, ss[device_id] {ss[device_id]}")
ss.device_s.append(ss[device_id]) # Append device ID to the list of devices
st.warning(f"ss[device_id].exp_ms: {ss[device_id].exp_ms}")
with st.sidebar.form(key='device_s'):
exp_ms = st.number_input("Exposure, ms", key='exp_ms',
value=ss[device_id].exp_ms,
min_value=0.1, max_value=65_000., step=100.,
format="%g")
st.error(f"exp_ms: {exp_ms}")
submit_button = st.form_submit_button(label='✔️ Run Acquisition')
if submit_button:
logger.info("Requested list of devices")
return submit_button
def main():
if 'is_initialized' not in ss:
ss.device_s = [] # List to store instances of Device class
ss.is_initialized = True
connect()
if "list_device_s" not in ss:
logger.debug(f"list devices not in session state")
st.stop()
select_setting_on: bool = select_settings()
if __name__ == '__main__':
main()
You are setting st.session_state.device_s elsewhere in your code, and then using that key for the form. This can be resolved by changing the form key to be anything that’s not already in session state, e.g. st.sidebar.form(key="device_s_form")
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.