The callback definition is refreshed on every runs, so the callback attached to the worker is replaced on each run.
The class-based callback was designed to solve these 3 problems through instance attributes:
to pass values from outside to inside the callback.
to pass values from inside to outside the callback.
to hold (cache) computationally expensive objects over multiple runs.
This design also simply solves 1 and 3.
For 1., variables outside the callback can be referred to from inside as the example code above.
For 3., such objects should be cached through Streamlit's built-in cache mechanism and passed to the callback in the same way as 1.
2 is the concern.
The shared state object (#478) is one option.
Something like the following.
The callback definition is refreshed on every runs, so the callback attached to the worker is replaced on each run.
The class-based callback was designed to solve these 3 problems through instance attributes:
This design also simply solves 1 and 3. For 1., variables outside the callback can be referred to from inside as the example code above. For 3., such objects should be cached through Streamlit's built-in cache mechanism and passed to the callback in the same way as 1.
2 is the concern. The shared state object (#478) is one option.