How to update some of the page

How can I update some of the interactive elements on the page?

My task is like this.

  1. get the file path from a st.text_input
  2. 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
  3. if the parse result is incorrect, user can input corrections in the text input
  4. 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.

You need to introduce state for that, either have a look here for an example (if you search state streamlit there are various non official implementations around):

Or use the new feature of 0.65 for query_params

1 Like

A post was split to a new topic: Problems with Bokeh demo