Adding a trace/second person in a callback

I have created a callback that is supposed to result in a horizontal bar chart. It works as follows

  1. The user chooses a player he wants to evaluate
  2. The user chooses categorical elements/statistics to evaluate – either through a template or customized

That works well. Now I want to add the option that the user can select a second player. Therefore, I would like to compare the two selected players in a horizontal bar chart. That is what I’m struggling with. How can I do that? If there’s any information missing to answer properly, please let me know. Here’s my code so far:

`@app.callback(
[Output(“percentile_chart”, “figure”)],
[Input(“metrics_selector”, “value”),
Input(“player”, “value”),
Input(“submit_button”, “n_clicks”)],
[State(“metrics”, “value”),
State(“percentile_chart”, “figure”)],
)

def update_graph(metrics_selector, player_selected, n_clicks, metrics):

if metrics_selector == "custom":
    df_bar = df_per.copy()
    df_player = df_bar[df_bar["ID"] == player_selected] 
    if type(player_selected)!=str:
         val = player_selected[0]
         player = df[df["ID"] == player]
    df_player = df_player[metrics]
    df_player_t = df_player.T
    df_player_t = df_player_t.reset_index(drop=False)
    df_player_t.columns = ["Metric", "PR"]
    metric = df_player_t["Metric"]
    pr = df_player_t["PR"]
    trace = dict(
        type="bar",
        #mode="markers",
        x=pr[0:],
        y=metric[0:],
        orientation="h",
        marker = dict(
            color = pr,
            colorscale = "burgyl",
            line=dict(
                color="#000000",
                width=1
            )
        )
    )
    layout_bar=copy.deepcopy(layout)
    layout_bar["title"] = player_selected

else:
    df_bar = bar_options[metrics]
    df_player = df_bar[df_bar["ID"] == player_selected]
    if type(player_selected)!=str:
        val = player_selected[0]
        player = df[df["ID"] == player]
    df_player_t = df_player.T
    df_player_t = df_player_t.reset_index(drop=False)
    df_player_t.columns = ["Metric", "PR"]
    metric = df_player_t["Metric"]
    pr = df_player_t["PR"]
    trace = dict(
        type="bar",
        x=pr[1:],
        y=metric[1:],
        orientation="h",
        marker=dict(
            color=pr[1:],
            colorscale="burgyl",
            line=dict(
                color="#000000",
                width=1
            )
        )
    )
    layout_bar = copy.deepcopy(layout)
    layout_bar["title"] = player_selected


return [go.Figure(data=trace, layout=layout_bar)]`