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â)))