How can I update some of the interactive elements on the page?
My task is like this.
- get the file path from a st.text_input
- load a json file (parser) and parse the file in the back, show the parse results in the webpage by st.write, and next to each st.write is a st.text_input
- if the parse result is incorrect, user can input corrections in the text input
- after the user input some or all corrections, click a ‘re-parse’ button, the parser is updated and save into json file, then go back to step 2), the parse results are updated wait for more corrections till another click on the button, and so on…
In the process above, I don’t want to lose the file path in step 1).
My code goes like this:
import streamlit as st
filepath = st.text_input("filepath:")
parser_info = json.load(open("parser.json"))
result = do_parse(parser_info, filepath) # returns a list of parse results
text_inputs = []
for r in result:
st.write(r) # display the parse results
st.text_input() # and provide a text input for corrections
if st.button("re-parse"): # wait for user clicking on button
for ti in text_inputs:
if ti: # only check the text input with correction
update_parser(parser_info, ti) # update parser_info by correction
json.dump(parser_info, open("parser.json", "w"))
By running it, the parser.json is updated correctly, but the webpage cannot reflect updated parsing results, unless I reload the page and enter the filepath again.
How can I update the parsing results upon clicking the button while keeping the filepath info? Thanks for any advice.