Slider doesn't update

Summary

In my code, I have an object of a custom class Streamer that connects and handles websocket messages. The code does some operations on the messages and creates some charts. Everything is good so far. However, I would like to introduce a slider so that the user can customize the range of values shown in the plotly.express figures.

The problem that I have is that the slider’s values do not get updated. I have created a mock code that reproduces the design of my more complicated code as well as the problem that I am experiencing.

Steps to reproduce

Code snippet:

import streamlit as st
from threading import Thread
from streamlit.script_run_context import add_script_run_ctx
import time

class Streamer:
    def __init__(self, placeholder):
        self.placeholder = placeholder

    def update(self, fake_message):
        with self.placeholder.container():
            st.metric(label="Fake message", value=fake_message)

    def stream(self):
        for second in range(200):
            fake_message = f'Fake_{second}'
            thr = Thread(target=self.update, args=(fake_message,))
            add_script_run_ctx(thr)
            thr.start()
            time.sleep(1)


st.set_page_config(
    page_title='Dashboard',
    layout='wide'
)

st.title("Dashboard")

placeholder = st.empty()

values = st.slider(
    'Select a range of values',
    0.0, 100.0, (25.0, 75.0))
st.write('Values:', values)

Streamer(placeholder).stream()

Expected behavior:

I expect that whenever the user selects a new range, this new range gets displayed.

Actual behavior:

The displayed range is the default range (25.0,75.0) and it does not respond to the changes of the user.

Debug info

Debug info

  • Streamlit version: 1.4.0
  • Python version: 3.10.4
  • OS version: MacOS 13.1
  • Browser version: Safari 16.2

Hello everyone,

I was wondering why this question is not getting an answer. Is it not clear maybe?
Please let me know

Thanks!

I use streamlit 1.17.0 on windows 10.

Also use:

from streamlit.runtime.scriptrunner.script_run_context import add_script_run_ctx

And reduce threads from 200 to 4.

for second in range(4):

That would update the values.

image

Perhaps it waits for the 200 threads to finish starting if you use 200.