I tried your code and it really sets to None, any idea why mine don’t? I cannot figure it out
This is where I define the dropdowns
def generate_dropdowns():
df = pd.read_csv("./data_source/NKFAM50Hz_Reduced.csv", encoding = "ISO-8859-1")
df.columns = ["product_number", "product_name", "pump_name", "actual_impeller", "min/max", "impeller", "poles", "flow_value",
"flow_unit", "head_value", "head_unit", "dnin", "dnout", "weight_value", "weight_unit", "speed_control", "rated_speed_value",
"rated_speed_unit", "motor_size_value", "motor_size_unit", "rpm_max", "q_min", "q_max", "points_speed_1/min", "q_bep_m3/h",
"eta2_bep_%", "h_bep_m", "p2_bep_kw", "n_bep_1/min", "rho_times_g", "qs", "hs", "p2s", "npshs", "ns", "q", "h", "p2", "npsh",
"coefficient_segment", "rpm_min", "head_poly", "power_poly", "npsh_poly", "poly_fit_image"]
product_names = []
actual_impellers = [impeller for impeller in df["actual_impeller"].unique().tolist()]
poles_numbers = [number for number in df["poles"].unique().tolist()]
speed_controls = [control for control in df["speed_control"].unique().tolist()]
for product_name in df['product_name'].tolist():
product_names.append(product_name.split("/")[0])
#getting the unique values
product_names = list(dict.fromkeys(product_names))
names = ["Product name", "Actual Impeller", "Number of Poles", "Speed Control"]
options = [
product_names,
actual_impellers,
poles_numbers,
speed_controls
]
dropdowns = []
disabled = False
for name, option_list in zip(names, options):
dropdowns.append(
dbc.Col([
html.Br(),
dbc.Col(html.Label(name), style = {"textAlign": "start"}),
dcc.Dropdown(
options = option_list,
clearable = True,
disabled = disabled,
id = {"type": "dropdown", "index": name.lower().replace(" ", "-")}
),
],
width = 3, lg = {"size": 3}, md = {"size": 4}, sm = {"size": 5},
),
)
return dropdowns
And this the callback
@app.callback(
Output({"type": "dropdown", "index": "product-name"}, "options"),
Output({"type": "dropdown", "index": "actual-impeller"}, "options"),
Output({"type": "dropdown", "index": "number-of-poles"}, "options"),
Output({"type": "dropdown", "index": "speed-control"}, "options"),
Input({"type": "dropdown", "index": "product-name"}, "value"),
Input({"type": "dropdown", "index": "actual-impeller"}, "value"),
Input({"type": "dropdown", "index": "number-of-poles"}, "value"),
Input({"type": "dropdown", "index": "speed-control"}, "value"),
State("store-dataset", "data"),
prevent_initial_call = True
)
def update_dropdowns(product_name, actual_impeller, number_of_poles, speed_control, dataset):
product_options = dash.no_update
impeller_options = dash.no_update
poles_options = dash.no_update
speed_options = dash.no_update
df = pd.read_csv("./data_source/NKFAM50Hz_Reduced.csv", encoding = "ISO-8859-1")
df.columns = ["product_number", "product_name", "pump_name", "actual_impeller", "min/max", "impeller", "poles", "flow_value",
"flow_unit", "head_value", "head_unit", "dnin", "dnout", "weight_value", "weight_unit", "speed_control", "rated_speed_value",
"rated_speed_unit", "motor_size_value", "motor_size_unit", "rpm_max", "q_min", "q_max", "points_speed_1/min", "q_bep_m3/h",
"eta2_bep_%", "h_bep_m", "p2_bep_kw", "n_bep_1/min", "rho_times_g", "qs", "hs", "p2s", "npshs", "ns", "q", "h", "p2", "npsh",
"coefficient_segment", "rpm_min", "head_poly", "power_poly", "npsh_poly", "poly_fit_image"]
df['poles'] = df['poles'].fillna(0)
df1 = pd.DataFrame.from_dict(dataset)
#value_when_true if condition else value_when_false
df1 = df1[df1["product_name"].str.contains(product_name)] if product_name is not None else df1
df1 = df1[df1["actual_impeller"] == actual_impeller] if actual_impeller is not None else df1
df1 = df1[df1["poles"] == number_of_poles] if number_of_poles is not None else df1
df1 = df1[df1["speed_control"].str.contains(speed_control)] if speed_control is not None else df1
product_options = []
for product_name in df1['product_name'].tolist():
product_options.append(product_name.split("/")[0])
#getting the unique values
product_options = list(dict.fromkeys(product_options))
impeller_options = [impeller for impeller in df1["actual_impeller"].unique().tolist()]
poles_options = [number for number in df1["poles"].unique().tolist()]
speed_options = [speed for speed in df1["speed_control"].unique().tolist()]
component_id = dash.callback_context.triggered[0]["prop_id"]
if "product-name" in component_id and product_name is not None:
print(product_name)
product_options = dash.no_update
elif "actual-impeller" in component_id and actual_impeller is not None:
impeller_options = dash.no_update
elif "number-of-poles" in component_id and number_of_poles is not None:
poles_options = dash.no_update
elif "speed-control" in component_id and speed_control is not None:
speed_options = dash.no_update
return product_options, impeller_options, poles_options, speed_options