Legend doesn't update for a piechart callback

Hey! I’m facing issues with updating my legend values correctly in a pie chart that I am making for a dashboard on the bokeh server.

The problem is pretty simple - I have a dynamic pie chart that updates as the value in a dropdown changes. The values in the pie chart change correctly, but the legend keeps the values for the option that was clicked the very first time in the dropdown.

From everything I read so far, I have been able to understand that I will need to create a legend manually, but I am pretty unsure of how to achieve this.

Here’s a stripped-down version of the code I’m using for the pie chart:

dropdown = Dropdown(label="Choose Activity", button_type="warning", menu=tasks)
a2 = figure(plot_height=350, toolbar_location=None, tools="hover")

def callback(new):

        data2 = pd.Series(x2).reset_index(name='value').rename(columns={'index':'PROCESSNAME'})
        data2['angle'] = data2['value']/data2['value'].sum() * 2*pi
        data2['color'] = Category20c[len(x2)]

        data2_cds = ColumnDataSource(data=data2)

        a2.wedge(x=0, y=1, radius=0.4,
                start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'),
                line_color="white", fill_color='color', source=data2_cds, legend_field = , legend_field = "PROCESSNAME")

        a2.axis.axis_label=None
        a2.axis.visible=False
        a2.grid.grid_line_color = None

I’d really appreciate some help on how I can make a correct legend for each of the options in my dropdown so the plot gets updated correctly every time the callback function is called.

Thank you !