Here are my functions:
def unit_select():
unit_select.unit = st.selectbox('Select unit for force', ('lbs', 'klbs', 'tons'))
def unit_convert(df):
if unit_select.unit == 'tons':
df['A'] = df['B'].apply(some_conversion_func)
elif unit_select.unit == 'klbs':
df['A'] = df['B'].apply(some_other_conversion_func)
else:
pass
return df
if option == 'Unit Conversion Panel':
unit_select()
unit_confirm = st.button('Confirm')
if unit_confirm:
df = upload_my_df() # I am loading my df using upload_my_df func which is not shown here
unit_convert(df)
I am getting an error ’ DuplicateWidgetID: There are multiple identical st.selectbox
widgets with the same generated key.’ because I am referring to the same function unit_select
multiple time in the func unit_convert
while checking for its value. Not sure how I can add the key attribute to the st.selectbox
in this particular scenario.