Show live class variable

Summary

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
            time.sleep(0.5)

my Streamlit code looks like this

from streamlitStepper import streamlitStepper
import streamlit as st
import threading

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

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

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.