As advised, I tested my function in Jupyter and it was broken (mainly casting in dataframe to float) and now it is fixed but it still ends up breaking my other callbacks when I add it back into.
@app.callback(
Output("nutrients-table", "children"),
[Input("add-ingredient", "n_clicks")],
[State("numerical-amount", "value"),
State('units-dropdown', 'value')],
)
def update_nutrients_table(num_clicks, amount, units):
'''
get multiplier from conversions table for correct units,
multiply by each nutrient by correct amount
conv_cols of Conversions: Name, Multiplier
'''
curr_nutrients_df = nutrients_df.copy().astype(str)
# todo: if n_clicks reset to zero check for <0 for remove ingredient
if num_clicks > 0:
measure_name = ''
measure_num = -1
curr_multiplier = ''
for index, row in conversions_df.iterrows():
if units in str(row['Name']):
# get number
measure_name = str(row['Name'])
measure_num = float(re.findall("\d+", measure_name)[0])
curr_multiplier = float(row['Multiplier'])
break
# divide amount/measure_num
multiplier_factor = (float(amount)) / measure_num
new_multiplier = multiplier_factor * curr_multiplier
# multiply all nutrients by new_multiplier
for index, row in curr_nutrients_df.iterrows():
new_row_val = float(row['Value']) * new_multiplier
row['Value'] = str(new_row_val)
# return updated_nutrients_table
# print(curr_nutrients_df.head)
return make_nutrients_table(curr_nutrients_df)
#not updated
return make_nutrients_table(curr_nutrients_df)