I’m trying to figure out how to keep hidden traces hidden when a Graph is redrawn through a callback. Consider a simple line chart (with multiple traces) with a RangeSlider that determines the range of the x-axis. If the user clicks a trace in the legend to turn it off, then moves the slider, the trace is turned back on (because the whole graph is redrawn). Is there a way to preserve the visibility of traces? I know that I can set
legendonly in each trace, but how do I read the existing visibility in the callback. It doesn’t seem to work to have the figure itself be an Input to the callback in which it is an Output.
Here’s a simple example:
import dash import dash_core_components as dcc import dash_html_components as html import cufflinks as cf cf.go_offline() app = dash.Dash() #some dummy data df = cf.datagen.lines() def test_plot(start=0, end=100): figure = df.iloc[start:end].iplot(asFigure=True) return figure app.layout = html.Div( [ dcc.Graph( id='test_graph', figure=test_plot() ), dcc.RangeSlider( id='test_slider', min=0, max=100, value=[0,100] ) ] ) @app.callback( dash.dependencies.Output('test_graph', 'figure'), #I'd like to be able to put the figure itself as an input here, so I could read the trace visibility and preserve it when creating the new figure. [dash.dependencies.Input('test_slider', 'value')]) def update_figure(value): return test_plot(value, value) if __name__ == '__main__': app.run_server(use_reloader=True)