I found what appears to be a bug with using relayoutData callbacks with Candlestick plots. A couple of things I noticed:
- If the candlestick plot isn't updated by an additional callback, relayoutData seems to work fine.
- relayoutData works correctly if the Candlestick figure is replaced by Scatter or a different plot style. As far as I can tell this is a bug related to Candlestick plots only.
What I'm working with:
dash_core_components ==0.28.0
dash_html_components== 0.11.0
dash== 0.26.2
plotly== 3.1.1
importpandasaspdimportnumpyasnpimportjsonimportdashimportdash_core_componentsasdccimportdash_html_componentsashtmlfromdash.dependenciesimportInput, Outputimportplotly.graph_objsasgoimportplotly# Data to plot# ------------------------------------------------------------------------------candles=pd.DataFrame(np.random.randint(1,100, size= (100,4)),
columns= ['open', 'close', 'high', 'low'])
# App# ------------------------------------------------------------------------------app=dash.Dash()
serv=app.serverapp.layout= \
html.Div([
html.Div([
html.Button('Reload', id='button')
]),
html.Div([
dcc.Graph(
id='candles_plot',
)
]),
html.Div([
dcc.Markdown("When Graph is updated by a callback, relayout doesn't work."),
html.Pre(id='relayout-data'),
], className='three columns'),
])
# Callbacks#-------------------------------------------------------------------------------@app.callback(dash.dependencies.Output('candles_plot', 'figure'), [dash.dependencies.Input('button', 'n_clicks')] )defupdate_plot(reload):
figure= {
'data':[
go.Candlestick(
x=candles.index,
open=candles.open,
high=candles.high,
close=candles.close,
low=candles.low
)
],
'layout':[
go.Layout(
xaxis=dict(
rangeslider= {'visible':False}
)
)
]
}
returnfigure@app.callback(Output('relayout-data', 'children'), [Input('candles_plot', 'relayoutData')])defdisplay_selected_data(relayoutData):
returnjson.dumps(relayoutData, indent=2)
if__name__=='__main__':
app.run_server(debug=True)
I found what appears to be a bug with using relayoutData callbacks with Candlestick plots. A couple of things I noticed:
What I'm working with:
dash_core_components ==0.28.0
dash_html_components== 0.11.0
dash== 0.26.2
plotly== 3.1.1