diff --git a/shapash/explainer/smart_plotter.py b/shapash/explainer/smart_plotter.py index 4d91c348..c030b543 100644 --- a/shapash/explainer/smart_plotter.py +++ b/shapash/explainer/smart_plotter.py @@ -1127,7 +1127,7 @@ def interactions_plot( >>> xpl.plot.interactions_plot(0, 1) """ - if not (isinstance(col1, str | int) or isinstance(col2, str | int)): + if not (isinstance(col1, str | int) and isinstance(col2, str | int)): raise ValueError("parameters col1 and col2 must be string or int.") col_id1 = self._explainer.check_features_name([col1])[0] diff --git a/shapash/webapp/smart_app.py b/shapash/webapp/smart_app.py index 59b13134..26591cb4 100644 --- a/shapash/webapp/smart_app.py +++ b/shapash/webapp/smart_app.py @@ -2340,7 +2340,7 @@ def update_feature_selector(feature, data, label, click_zoom, points, violin, gf Input("reset_dropdown_button", "n_clicks"), Input({"type": "del_dropdown_button", "index": ALL}, "n_clicks"), ], - [State("dataset", "data"), State("index_id", "value")], # Get the current value of the index + [State("dataset", "data"), State("dataset", "derived_viewport_data"), State("index_id", "value")], ) def update_index_id( click_data, @@ -2351,6 +2351,7 @@ def update_index_id( reset_filter, nclicks_del, data, + viewport_data, current_index_id, ): """ @@ -2364,7 +2365,8 @@ def update_index_id( apply_filters: click on Apply filter button reset_filter: click on reset filter button nclicks_del: click on del button - data: dataset + data: dataset (original order) + viewport_data: dataset as currently displayed (after sorting/filtering) current_index_id: the current value of the index ---------------------------------------------------------------- return @@ -2381,7 +2383,7 @@ def update_index_id( elif ctx.triggered[0]["prop_id"] == "clusters.clickData": selected = clusters["points"][0]["customdata"] elif ctx.triggered[0]["prop_id"] == "dataset.active_cell": - selected = data[cell["row"]]["_index_"] + selected = viewport_data[cell["row"]]["_index_"] elif ("del_dropdown_button" in ctx.triggered[0]["prop_id"]) & (None in nclicks_del): selected = current_index_id except KeyError: @@ -2614,9 +2616,9 @@ def toggle_modal_id_card(n1, n2, is_open): Output("dataset", "style_cell_conditional"), ], [Input("validation", "n_clicks")], - [State("dataset", "data"), State("index_id", "value")], + [State("dataset", "data"), State("dataset", "derived_viewport_data"), State("index_id", "value")], ) - def datatable_layout(validation, data, index): + def datatable_layout(validation, data, viewport_data, index): ctx = dash.callback_context if ctx.triggered[0]["prop_id"] == "validation.n_clicks" and validation is not None: pass @@ -2638,7 +2640,8 @@ def datatable_layout(validation, data, index): ] style_cell_conditional = [{"if": {"column_id": c}, "fontWeight": "bold"} for c in self.special_cols] - selected = check_row(data, index) + # Use viewport_data (sorted/filtered) to find the correct row index for highlighting and not the index of the list + selected = check_row(viewport_data if viewport_data is not None else data, index) if selected is not None: style_data_conditional += [{"if": {"row_index": selected}, "backgroundColor": self.color[0]}]