-
-
Notifications
You must be signed in to change notification settings - Fork 74
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
So I made this minimal example but I can not figure out why I can't get the callbacks to work.
`
"""
Minimal dynamic dash app example.
"""
import numpy as np
import plotly.graph_objects as go
import trace_updater
from dash import Dash, Input, Output, State, dcc, html
from plotly_resampler import FigureResampler
x = np.arange(1_000_000)
noisy_sin = (3 + np.sin(x / 200) + np.random.randn(len(x)) / 10) * x / 1_000
app = Dash(__name__)
fig = FigureResampler(go.Figure(go.Scatter(x=x, y=noisy_sin)))
app.layout = html.Div(
[
html.Div(
children=[
html.Button("Add Chart", id="add-chart", n_clicks=0),
]
),
html.Div(id="container", children=[]),
]
)
@app.callback(
Output("container", "children"),
Input("add-chart", "n_clicks"),
State("container", "children"),
)
def display_graphs(n_clicks: int, div_children: list[html.Div]) -> list[html.Div]:
"""
This function is called when the button is clicked. It adds a new graph to the div.
"""
figure = fig
figure.register_update_graph_callback(
app=app,
graph_id=f"graph-id-{n_clicks}",
trace_updater_id=f"trace-updater-id-{n_clicks}",
)
new_child = html.Div(
children=[
dcc.Graph(id=f"graph-id-{n_clicks}", figure=fig),
trace_updater.TraceUpdater(
id=f"trace-updater-id-{n_clicks}", gdID=f"graph-id-{n_clicks}"
),
],
)
div_children.append(new_child)
return div_children
if __name__ == "__main__":
app.run_server(debug=True)
`
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested