I’m a new dash user and have been enjoying using dash and reading through the forum.
I have a quick question regarding figure return and specifically why I can’t get the figure xaxis to update from the slider.
I’ve tried creating a new figure completely, using the update function or explicit assignment but none seem to work. Any help to understand what I’m missing would be appreciated.
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as goapp = dash.Dash()
app.layout = html.Div([dcc.RangeSlider( id='range-slider', min=0, max=30, value=[1.5, 5], pushable=2, updatemode='drag' ), html.Div([ dcc.Graph( id='example1', figure={ 'data': [ go.Scatter(x=[1,2,3], y=[4,5,6])], 'layout': [ go.Layout(title='test')], } ), ]), html.Div( id='slider-output')
])
@app.callback(
dash.dependencies.Output(‘example1’, ‘figure’),
[dash.dependencies.Input(‘range-slider’, ‘value’)])
def update_fig(value, figure):
value1 = value[0]
value2 = value[1]
figure[“layout”].update(xaxis={‘range’: [value1, value2]})return figure
if name == ‘main’:
app.run_server(debug=True)
or this
figure[‘layout’][‘xaxis’][‘range’] = [value1, value2]
return figure
or this
figure={ 'data': [ go.Scatter(x=[1,2,3], y=[4,5,6])) ], 'layout': go.layout( xaxis={'range': [value1, value2]} ) }
return figure