I want to persist height
of my plotly graph in local storage.
app = DjangoDash("Chart")
HEIGHT = [480, 600, 720, 864, 1024, 1152, 1280, 1440, 1920, 2560]
app.layout = html.Div(
children=[
dcc.Store(id="height-value", storage_type="local"),
dcc.Dropdown(HEIGHT, id="height-select"),
dcc.Graph(id="graph", config={"responsive": True}),
],
)
@app.callback(
Output("height-value", "data"),
Input("height-select", "value"),
)
def update_height(height):
if not height:
return 480
return height
@app.callback(
Output("graph", "figure"),
Input("height-value", "data"),
)
def update_figure(height):
fig = go.Figure(
...
)
fig.update_layout(
height=height,
)
return fig
But I can’t figure out how to initialize height-select
with data
from height-value
. What is the corect approach here?