Get trace name from clickdata

I am also getting this error when I am using a callback to use the clickData to get the trace name from the figure. I followed These Instructions

Traceback: AttributeError: 'Graph' object has no attribute 'figure'

right_graph_div = html.Div(id='output-div',children=[dcc.Graph(id='output-figure')],
                           style={'width': '75%', 'float': 'right', 'display': 'inline-block'})

import json
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div([
    html.Div([
        html.Div([
            left_button_div,
            right_graph_div
        ]),
        html.Div(id='test', style={'width': '100%', 'display': 'inline-block'})
    ])
])

@app.callback(
    Output(component_id='output-figure', component_property='figure'),
    [Input(component_id='xaxis-column', component_property='value'),
    Input('agg-func', 'value'),
    Input('color-by', 'value')]
)

def update_output_div(x_axis_col, agg_func, color_by):
    
    if agg_func.lower() == 'count':
        x_axis_col = x_axis_col.lower().replace(' ', '_')
        fig = make_creative_count_plot(df, count_by_dimension=x_axis_col, 
                                       color_by=color_by.lower().replace(" ", "_"))
        return fig
    
@app.callback(
    Output('test', 'children'),
    [Input('output-figure', 'clickData')])

def display_click_data(click_data):
    
    if click_data is not None:
        curve_number = click_data['points'][0]['curveNumber']
        x_value = click_data['points'][0]['x']

### THIS IS WHERE THE ERROR OCCURS
        trace_name = json.dumps(app.layout['output-figure'].figure['data']) 
        return curve_number, ' ', x_value, ' ', trace_name


if __name__ == '__main__':
    app.run_server(debug=False)

The make_creative_count_plot() function builds a figure with fig = make_subplots(specs=[[{"secondary_y": True}]])

I add a variable number of traces depending on user input. This section:

curve_number = click_data['points'][0]['curveNumber']
 x_value = click_data['points'][0]['x']

Outputs the expected data from the clickData. I just can’t access the figure data from the first callback figure output.

The figure generates and dynamically changes as expected.