Show live class variable


Hi there!
I use a Steppermotor and would like to show the actual position (every step while moving) in a “metric” container. The code snippet is a simple example how my Steppermotor works. When moving to a position it updates the position value for each step.

Thx in andvance!
Bests Moritz

Steps to reproduce

Code snippet:

import time
class streamlitStepper(object):

    position = 0

    def __init__(self, position):
        self.position = position
    def move(self, steps, direction):
        for i in range(steps):
            self.position = self.position + 1

my Streamlit code looks like this

from streamlitStepper import streamlitStepper
import streamlit as st
import threading

Stepper = streamlitStepper()
if st.button(label='Move'):
    moveThread = threading.Thread(target=Stepper.move, args=(10,1,))
placeholder = st.empty()

with placeholder.container():
    StepperPos = Stepper.position
    st.metric(label='Position', value = StepperPos)