Announcing Dash Bio 1.0.0 🎉 : a one-stop-shop for bioinformatics and drug development visualizations.

How to prevent traces from coming back after being disabled in a live graph

I have a simplified version of my program below where the graph being showed is updated once every second. When I click the name “y1” or “y2” on the right side of the graph the corresponding trace in the graph disappear which is what I want, but how can I modify the code below to prevent the trace from coming back after one second? I only want the trace to come back when I click the name “y1” or “y2” one more time. Thanks in advance!

import dash
from dash.dependencies import Output, Input
from dash import dcc
from dash import html
import plotly.graph_objects as go

x_time=["09:31:00", "09:32:00", "09:33:00", "09:34:00", "09:35:00"]

app = dash.Dash(__name__)
app.layout = html.Div(
        dcc.Graph(style={'height': '100vh'}, id = 'live-graph', animate = False),
            id = 'graph-update',
            interval = 1000,
            n_intervals = 0

@app.callback(Output('live-graph', 'figure'),
              Input('graph-update', 'n_intervals'))
def update_graph_scatter(n):
    fig = go.Figure(go.Scatter(x=x_time, y=y1, mode='lines', name='y1', line=dict(color="#ff0000")))
    fig.add_trace(go.Scatter(x=x_time,   y=y2, mode='lines', name='y2', line=dict(color="#00ff00")))
    return fig

if __name__ == '__main__':


You can just set the uirevision in your figure layout:


For some extra info about it, please check this post.