How do I append new data points i.e. x axis and y axis values coming from input fields using a clientside_callback function. I am currently trying something like this but it is not updating the data in real time the updated data points show when I double click on the legend of the trace that is being updated ( due to the click the trace re-renders )
Code:
dash.register_page(__name__, path='/barchart-render')
# Page Layout for Different Filters and Dropdown Selections
def layout(**query_strings):
layout = html.Div(
[
html.Div(
children=[
html.H5('Label'),
dcc.Input(
id='Label',
style={'height': "50px", "width": "150px"}
),
html.H5('Value'),
dcc.Input(
id='Value',
style={'height': "50px", "width": "150px"}
),
dbc.Button(
id='High-button',
children="Update Chart",
n_clicks=0,
className='button'
)
]
),
html.Div(
children=[
dcc.Loading(
id="loading-graph",
children=[
html.Div(
dcc.Graph(id="barchart-graph-component", figure=BarChart),
className="graph",
)
],
type="cube",
fullscreen=True,
color="#2a9d8f"
)
],
className="main-graph-component card bg-secondary mb-3"
)
],
className="main-layout-div"
)
return layout
clientside_callback(
"""
async function(n_clicks, label, value, figure) {
console.log('n_clicks', n_clicks);
if (n_clicks > 0 & label !== undefined & label !== 0 & value !== undefined & value !== 0 ) {
value = parseInt(value);
console.log(label, value);
console.log('figure', figure);
figure.data[0].x = [...figure.data[0].x, label];
figure.data[0].y = [...figure.data[0].y, value];
console.log('updated Figure', figure);
return figure, 0;
};
return figure, 0;
}
""",
Output('barchart-graph-component', 'figure'),
Output('High-button', 'n_clicks'),
Input('High-button', 'n_clicks'),
State('Label', 'value'),
State('Value', 'value'),
State('barchart-graph-component', 'figure')
)