I am trying to save user inputs to json file for next session. When I save number input and import it, there is no problem, it works fine. I have select box user inputs too. It works well when I deleted the json file and run the code. However, it gives the error on screenshot when I change inputs. When I open the json file to check if it saves correctly, it looks ok
here the first run everything is ok
here is what I see after changing the inputs
code to save number input
x = st.number_input(âxâ, value=user_inputs.get(âxâ,1267.41))
user_inputs[âxâ] = x;
code to save select box input
ent_type = st.selectbox(âEnterance Typeâ,user_inputs.get(âent_typeâ,(âcircular bellmountâ,âsquare bellmountâ,âr/D>=0.15 entranceâ,âslightly roundedâ,âsquare corneredâ)))
user_inputs[âent_typeâ] = ent_type
Note that the function save_ent_type saves the index of the selected option whenever the st.selectbox changes. The example uses Streamlitâs session state, but hopefully you can convert to your use case with json files. Let me know!
I tried the following and solved the problem thanks to chat gpt
ent_opt = (âcircular bellmountâ,âsquare bellmountâ,âr/D>=0.15 entranceâ,âslightly roundedâ,âsquare corneredâ)
ent_type = st.selectbox(f"Enterance Type{id}â, ent_opt, index=ent_opt.index(user_inputs.get(f"ent_type{id}â, âcircular bellmountâ)))
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.