dash == 2.8.1 jupyter-dash == 0.4.2 044acaa
Greetings! I’ve faced with a problem of accessing a python object from my jupyter-dash application when I use
To illustrate: we have some class
Error_test that initialize some variable
number = 0 and when we run function
add_number, 1 is added to this variable every second.
import time class Error_test: def __init__(self): self.number = 0 def add_number(self): while 1: time.sleep(1) self.number += 1
Then I create a simple jupyter-dash app that just shows the current state of this variable using
from dash import dcc, html, callback from dash.dependencies import Input, Output from jupyter_dash import JupyterDash app = JupyterDash(__name__) def conf_test_app(error_test): def serve_layout(): return html.Div( [ html.Div(id="placeholder"), dcc.Interval(id="interval-update", interval=1000, n_intervals=0), ] ) @callback( Output("placeholder", "children"), Input("interval-update", "n_intervals") ) def update_number_data(i): return error_test.number app.layout = serve_layout() return app
When I create new instance of this class and send it to app
test = Error_test() app = conf_test_app(error_test=test) app.run(mode="inline")
and then run the function
test.add_number() - it works just fine and we see that every second the div component updates.
Then I re-run jupyter cell with
test = Error_test() (basically recreate python object,
number = 0 again) and refresh jupyter-dash app, but
Div component shows the previous state of variable
number, not 0…
The thing is that if we will print
update_number_data callback, it would show the previous id of
I think it is very strange behaviour. Is it a bug or I’m doing something wrong?