Update elements like header and signal handling

Hello,
I have two questions. I am building a dashboard to view realtime data generated by a particular function which continuously runs in a while loop.

  1. Change values corresponding to a given header without rewriting the entire header or title
  2. Using signals to exit my indefinite while loop gives,

ValueError: signal only works in main thread

Snippet for problem-1:

st.header("Value of element-1: {}".format(val))

while True:
    foo()
    val = val+1

How to modify the code to change the val in the st.header

Thanks!