Exemple #1
0
    html.Button(id="btn-run", children="Take a nap"),
    # Container for storing the result of the async job.
    html.Div(id="div-result"),
    # Container for storing a reference to the async job.
    dcc.Store(id="result-tuple"),
    # Interval component for polling updates on the status of the async job.
    dcc.Interval(id="poller", max_intervals=0),
])


@app.callback([
    Output("btn-run", "disabled"),
    Output("btn-run", "children"),
    Output("result-tuple", "data"),
    Output("poller", "max_intervals")
], [Input("btn-run", "n_clicks")], [State("nap-duration", "value")])
def launch_job(n_clicks, value):
    # Run the job asynchronously (note the .delay syntax).
    result = take_a_nap.delay(value)
    # Disable button and set text (or start a spinner, etc.), save result reference, and start polling.
    return True, "Napping...", result.as_tuple(), -1


@app.callback([
    Output("btn-run", "disabled"),
    Output("btn-run", "children"),
    Output("div-result", "children"),
    Output("poller", "max_intervals")
], [Input("poller", "n_intervals")], [State("result-tuple", "data")])
def poll_result(n_intervals, data):
    result = result_from_tuple(data, app=celery_app)
Exemple #2
0
from dash_extensions.enrich import DashProxy
from dash_extensions.enrich import Input, Output

import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc

# Create app.
app = DashProxy()
app.layout = dbc.Container([
    dbc.Row(html.Br()),
    dbc.Row(dcc.Input(id="input"), justify="around"),
    dbc.Row(html.Div(id="output"), justify="around"),
],
                           fluid=True)


@app.callback(Output("output", "children"), [Input("input", "value")])
def hello(value):
    return f"APP says: Hello {value}!"


if __name__ == '__main__':
    app.run_server()
import dash_html_components as html
from dash_extensions.enrich import Output, Dash, Input

app = Dash(prevent_initial_callbacks=True)
app.layout = html.Div([html.Button("Click me", id="btn"), html.Div(id="log")])


@app.callback(inputs=Input("btn", "n_clicks"),
              output=Output("log", "children")
              )  # inverted order of Output/Input is OK
def func(n_clicks):
    return f"Click count = {n_clicks}"


if __name__ == '__main__':
    app.run_server()
def make_callback(i):
    @app.callback(Output({'type': 'div', 'id': ALL}, 'children'), Input({'type': f'button{i}', 'id': ALL}, 'n_clicks'))
    def func(n):
        return [f"Hello from group {i}"] * len(n)