Is there any way to limit the data that is shown in the graph ?, It show me data from 3 days ago and I would like it to only show a certain amount, the most current, because if not then the graph is very saturated.
This is my code:
app = dash.Dash(
__name__,
server = server,
routes_pathname_prefix='/dashHUM/'
)
app.layout = html.Div("My Dash app")
app.layout = html.Div(children=[
html.H1(children='Sensores Libelium ',
style={
'textAlign': 'center',
'color': colors['text']
}, className='banner'),
html.H3(children='Dash: Humedad', style={
'textAlign': 'center',
'color': colors['text']
}),
html.Div([
html.Div([
html.H2("%", style={
'color': colors['text']
})
], className='Title'),
html.Div([
dcc.Graph(id='example-graph1'),
], className='twelve columns wind-speed'),
dcc.Interval(id='graph-update1', interval=1000, n_intervals=0),
], style={'padding': '0px 10px 15px 10px'},className='row wind-speed-row'),
], style={'padding': '0px 10px 15px 10px',
'marginLeft': 'auto', 'marginRight': 'auto', "width": "1100px",
'boxShadow': '0px 0px 12px 5px rgba(204,204,204,0.4)',
'background': 'rgba(247,247,247,0.6)'})
@app.callback(Output('example-graph1', 'figure'),
[Input('graph-update1', 'n_intervals')])
def update_graph1(interval):
now = dt.datetime.now()
sec = now.second
minute = now.minute
hour = now.hour
total_time = (hour * 3600) + (minute * 60) + (sec)
dataSQL = []
X = deque(maxlen=10)
Y = deque(maxlen=10)
sql_conn = MySQLdb.connect('localhost', 'root', 'password', 'DB')
cursor = sql_conn.cursor()
cursor.execute("SELECT value,timestamp FROM sensorParser where sensor='HUM'")
rows = cursor.fetchall()
for row in rows:
dataSQL.append(list(row))
labels = ['value','timestamp']
df = pd.DataFrame.from_records(dataSQL, columns=labels)
X = df['timestamp']
Y = df['value']
data = plotly.graph_objs.Scatter(
x=list(X),
y=list(Y),
name='HUM',
mode= 'lines+markers'
)
return {'data': [data],'layout' : go.Layout(title="HUMEDAD",xaxis=dict(range=[min(X),max(X)]),
yaxis=dict(range=[min(Y),max(Y)]),)}
Regards.