Hi, I must have looked everywhere for a simple explanation on how this works. I have an example where I think I’m close to a solution, but I can’t seem to get it to work. Any ideas?
Here is my code so far. I basically just want the yaxis to autoscale to the data beeing shown while working the rangeslider. Thanks a lot for the help =) Any suggestions on a simpler way of doing this is also much appretiated. I’m pretty to new to dash, so I’m sure there’s better ways of doing it.
import dash
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import numpy as np
import datetime
#some random values
a = datetime.datetime.today()
numdays = 100
dateList = []
for x in range (0, numdays):
dateList.append(a - datetime.timedelta(days = x))
xy = [dateList,np.random.rand(100)]
app = dash.Dash()
app.title = 'Random'
dataS = go.Scatter(
x = xy[0],
y = xy[1],
name = 'Rand',
mode = 'lines'
)
layoutS = go.Layout(
title="Rand",
xaxis=dict(
rangeslider_visible=True,
rangeselector=dict(
buttons=list([
dict(count=1, label="1m", step="month", stepmode="backward"),
dict(count=6, label="6m", step="month", stepmode="backward"),
dict(count=1, label="YTD", step="year", stepmode="todate"),
dict(count=1, label="1y", step="year", stepmode="backward"),
dict(count=5, label="5y", step="year", stepmode="backward"),
dict(step="all")
])
)
)
)
app.layout = html.Div(
html.Div([
html.H1(children='Random nums'),
html.Div(children='''
Rand rand rand.
'''),
dcc.Graph(id='RandGraph', animate=True, figure=go.FigureWidget(data=dataS,layout=layoutS))
])
)
@app.callback(Output('RandGraph','figure'),[Input('RandGraph','relayoutData')])
def update_graph(relOut):
layout = go.Layout(
yaxis=dict(range=[0,2])
)
return {'layout':layout}
if __name__ == '__main__':
app.run_server(debug=False)
1 post - 1 participant