I know this is an old problem, but it just bit me and i couldnt find a proper solution.
Anyways after trying some stuff i found a decent solution myself:
Instead of updating the figure, or dcc.Graph i now update the entire html.div.
I have taken your example and fixed it to show it, see below.
I have also done some testing:
When i add a random number to the id it works aswell. So i am guessing the callback somehow remembers the graph id, so when you press reset axes it looks back to the first time it generated that graph instead of the last time it was updated via a callback. When you update the div that contains the graph this somehow breaks.
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
import math
app = dash.Dash(name)
server = app.server
app.title = āresetScale2d Testā
_config = {āmodeBarButtonsā: [[āresetScale2dā]]}
def make_fig(plot_type=ālinearā, x=range(21), y=range(1, 211, 10)):
xvals = list(x)
yvals = list(y)
xrange = [0, 50]
yrange = [1, 500]
if plot_type == ālogā:
yrange = [math.log10(yr) for yr in yrange]
print(plot_type, xrange, yrange)
traces = [go.Scatter(x=xvals, y=yvals, marker={āsizeā: 8}, name=āTensā)]
layout = go.Layout(
xaxis=dict(range=xrange),
yaxis=dict(type=plot_type,
range=yrange),
# uirevision=plot_type
)
fig = go.Figure(data=traces, layout=layout)
fig_div = html.Div(
[dcc.Graph(id='linlogplot', figure=fig, config=_config)],
id='fig_div',
)
return fig_div
app.layout = html.Div(
[
dcc.Dropdown(
id=ālinlogā,
options=[
{ālabelā: āLinear Plotā, āvalueā: ālinearā},
{ālabelā: āLog Plotā, āvalueā: ālogā},
],
value=ālinearā,
),
make_fig(),
]
)
@app.callback(Output(āfig_divā, āchildrenā), [Input(ālinlogā, āvalueā)])
def change_type(plot_type):
return make_fig(plot_type=plot_type)
if name == āmainā:
app.run_server()