Hi guys
First time posting here.
I’m building an application where I want to be able to save the input values in a json file, so I later can reload the values. I managed to get it to work with “session_state” and given the input values “key names”
See code below:
import streamlit as st
import json
def set_values_from_json():
file = st.session_state["file_uploader"]
if file:
if file.id != st.session_state["file_id"]:
json_dir = json.loads(file.read())
st.session_state["some_input"] = json_dir["some_value"]
st.session_state["some_other_input"] = json_dir["some_other_value"]
st.session_state["file_id"] = file.id
if "file_id" not in st.session_state:
st.session_state["file_id"] = -1
st.number_input(
"some_input",
key="some_input",
)
st.number_input(
"some_other_input",
key="some_other_input",
)
file = st.file_uploader(
"input json!", key="file_uploader", on_change=set_values_from_json
)
However, I keep getting a “The widget with key “some_input” was created with a default value but also had its value set via the Session State API.” warning the first time I load my json. Is there a way around this? Ether suppresses the warning or an alternative approach that doesn’t resolve in a warning?
Bonus question: The file_uploader “on_change” seems to trigger every time when it holds a file, not only when the file is changed. Is this a bug or intentional?