plotly / dash

Data Apps & Dashboards for Python. No JavaScript Required.
https://plotly.com/dash
MIT License
21.08k stars 2.04k forks source link

Long callback doesn't work in jupyter notebook #2056

Open wslabik opened 2 years ago

wslabik commented 2 years ago

Describe your context Please provide us your environment, so we can easily reproduce the issue.

Describe the bug

'running options’ in long callback are not working correctly when used with JupyterDash

Expected behavior

'running options' in long callbacks should work the same way in JupyterDash as they work in regular Dash

Screenshots

Cell output in the jupyter notebook (button is never enabled): Capture

Error which showed in the cell after a while of running:

ProcessLookupError: [Errno 3] assume no such process (originated from NtQuerySystemInformation (no PID found))

During handling of the above exception, another exception occurred:

NoSuchProcess                             Traceback (most recent call last)
NoSuchProcess: psutil.NoSuchProcess process no longer exists (pid=10268)

Here example 2 from the official guide changed to use JupyterDash instead of Dash, where button is never re-enabled (the 'running option' which should been applied at the end of the callback):

from jupyter_dash import JupyterDash
import time
import dash
from dash import html
from dash.long_callback import DiskcacheLongCallbackManager
from dash.dependencies import Input, Output
import diskcache

cache = diskcache.Cache("./cache")
long_callback_manager = DiskcacheLongCallbackManager(cache)

app = JupyterDash(__name__, long_callback_manager=long_callback_manager)

app.layout = html.Div(
    [
        html.Div([html.P(id="paragraph_id", children=["Button not clicked"])]),
        html.Button(id="button_id", children="Run Job!"),
    ]
)

@app.long_callback(
    output=Output("paragraph_id", "children"),
    inputs=Input("button_id", "n_clicks"),
    running=[
        (Output("button_id", "disabled"), True, False),
    ],
)
def callback(n_clicks):
    time.sleep(2.0)
    return [f"Clicked {n_clicks} times"]

if __name__ == "__main__":
    app.run_server(debug=True, mode='inline', port=2006)
T4rk1n commented 2 years ago

To validate with the new background callbacks.

ws-rio commented 3 months ago

@T4rk1n The issue persists with background callbacks the behaviour is different though - it now cannot find functions or modules imported outside the callback

see https://community.plotly.com/t/background-callback-doesnt-work-with-jupyter-dash/78432/12

any workaround for this? where to look for a potential fix?

dash                         2.17.0
dash-bootstrap-components    1.5.0
dash-bootstrap-templates     1.1.2
dash-core-components         2.0.0
dash-html-components         2.0.0
dash-loading-spinners        1.0.0
dash-table                   5.0.0