-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plot's ranges fail to resize when updating a Graph's figure with animate=True #68
Comments
Ah yeah. There is an issue in the plotly.js repo to make this better: plotly/plotly.js#1849 |
For now, try either:
Here's an example that shows how each of these works. The left is the former, the right is the latter import dash
import dash_core_components as dcc
import dash_html_components as html
import numpy as np
app = dash.Dash()
value_range = [-5, 5]
app.layout = html.Div([
html.Div([
html.Div(dcc.Graph(animate=True, id='graph-1'), className="six columns"),
html.Div(dcc.Graph(animate=True, id='graph-2'), className="six columns")
], className="row"),
dcc.RangeSlider(
id='slider',
min=value_range[0],
max=value_range[1],
step=1,
value=[-2, 2],
marks={i: i for i in range(value_range[0], value_range[1]+1)}
)
], className="container")
trace = {
'mode': 'markers',
'marker': {
'size': 12,
'opacity': 0.5,
'line': {
'width': 0.5,
'color': 'white'
}
}
}
@app.callback(
dash.dependencies.Output('graph-1', 'figure'),
[dash.dependencies.Input('slider', 'value')])
def update_graph_1(value):
x = np.random.rand(50) * (value[1] - value[0]) + value[0]
y = np.random.rand(50) * (value[1] - value[0]) + value[0]
return {
'data': [dict({'x': x, 'y': y}, **trace)],
'layout': {
'xaxis': {'range': [np.min(x), np.max(x)]},
'yaxis': {'range': [np.min(y), np.max(y)]}
}
}
@app.callback(
dash.dependencies.Output('graph-2', 'figure'),
[dash.dependencies.Input('slider', 'value')])
def update_graph_1(value):
x = np.random.rand(50) * (value[1] - value[0]) + value[0]
y = np.random.rand(50) * (value[1] - value[0]) + value[0]
return {
'data': [dict({'x': x, 'y': y}, **trace)],
'layout': {
'xaxis': {'range': value_range},
'yaxis': {'range': value_range}
}
}
app.css.append_css({"external_url": "https://codepen.io/chriddyp/pen/bWLwgP.css"})
if __name__ == '__main__':
app.run_server(debug=True) |
I have a related error when using |
I'm going to close this in favor of plotly/plotly.js#1849 |
I have a callback that updates the figure of a Graph by slicing the data to take a much smaller subset. When the callback is triggered, the range of the updated plot does not automatically resize when the Graph has
animate=True
. If I omit the animate param the range resizes fine.The text was updated successfully, but these errors were encountered: