Switching b/w ColumndataSources through callbacks

Here’s how the my implementation should work,

  1. The bokeh server starts running with a default csv file as input and the plots show up
  2. When I add files through fileInput, the columndatasource gets replaced by the columndatasource created by the new file and the plots get updated.

Here’s my callback function

plt1 = fig.circle(x="U(lambda)", y="V(lambda)", color="colors",
                  source=src1, size=6)

def upload_regular_data(attr, old, new):
    new_list=[]
    for file in new:
        f = io.BytesIO(b64decode(file))
        new_list.append(f) 
    df_2 = pd.concat(\
        map(lambda file: pd.read_csv(file,names=csv_fields,skiprows=2),new_list))
    df_2['r'] = np.sqrt(df_2.u**2 + df_2.v**2)
    df_2.columns = csv_fields
    df_2 = df_2.assign(colors="black")
    for sites, color in uvfitscode_color.items():
        df_2.loc[((df_2["T1"] == sites[0]) |
                (df_2["T1"] == sites[1])) & ((df_2["T2"] == sites[0]) |
                                        (df_2["T2"] == sites[1])), "colors"] = color

    df_final_2 = pd.concat([df_2, mirror_uv(df_2)])
    src2 = bm.ColumnDataSource(df_final_2)
    plt1.source=src2


file_input = FileInput(accept=".csv,.json,.txt,.pdf,.xls,.uvfits,.v6", multiple=True)
file_input.on_change('value', upload_regular_data)

I’m sure my code works until the last line of upload_regular_data() as I’ve seen the print statements of src2.data and df_final_2

What do I need to change for the plots to be updated?

Swapping out entire CDS is a very heavyweight operation and not well suppored, we may simply disallow it altogether at some point in the future. Best practice with Bokeh is to update the .data property of the existing CDS.

src1.data = new_data_dict

This pattern is illustrated all throughout the docs and examples and is maintained heavily under test.