Title Not Updating with Dash callback

Hello,
Newbie here. I just try to update the title of a plot in a callback. The title is clearly modified in the callback but the layout does not change in the output. And I really do not get why.

I looked for similar issues but I did not find anything.

Can you please help ? Here is a simplified example :

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

app = dash.Dash()
app.layout = html.Div([
dcc.Graph(id=‘output-graph’,
#config={‘displayModeBar’: False},
animate=True,
figure=go.Figure(
data=[go.Bar(x=[1, 2, 3], y=[1, 3, 2])],
layout=dict(title=dict(text=“ini title”))
)
),
dcc.Dropdown(
id=‘label-simu’,
options=[
{‘label’: ‘label1’, ‘value’: ‘title1’},
{‘label’: ‘label2’, ‘value’: ‘title2’},
{‘label’: ‘label3’, ‘value’: ‘title3’}
],
value=‘title2’
)
])

@app.callback(
dash.dependencies.Output(‘output-graph’, ‘figure’),
[dash.dependencies.Input(‘label-simu’, ‘value’)])
def update_output_ts(label):
fig = go.Figure(
data=[go.Bar(x=[1, 2, 3], y=[3, 3, 3])],
layout=dict(title=dict(text=str(label)))
)

#fig.update_layout(title_text=str(label))
#fig['layout']['title']['text'] = str(label)
#print(str(label))
print(fig['layout']['title']['text'])

return fig

if name == ‘main’:
app.run_server(debug=False)

Hi @vanis1 and welcome to the Dash Community!

It’s no longer recommended to use animate=True . If you take it out, the title should update as expected.

More info here: https://github.com/plotly/dash-docs/issues/660

1 Like