diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3445835 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + }, + "python.formatting.provider": "none" +} diff --git a/dashboard7/main.py b/dashboard7/main.py index 441defd..812c579 100644 --- a/dashboard7/main.py +++ b/dashboard7/main.py @@ -21,10 +21,21 @@ df = pd.DataFrame( ) # define cluster colors +# https://loading.io/color/feature/Spectral-10/ +COLORS = { + "0": "#9e0142", + "1": "#d53e4f", + "2": "#f46d43", + "3": "#fdae61", + "4": "#fee08b", + "5": "#e6f598", + "6": "#abdda4", + "7": "#66c2a5", + "8": "#3288bd", + "9": "#5e4fa2", +} -COLORS = {"0": "red", "1": "blue", "2": "grey"} - -X, y = make_blobs(n_samples=100, centers=3, n_features=2, random_state=0) +X, y = make_blobs(n_samples=300, centers=3, n_features=2, random_state=0) cluster_df = pd.DataFrame(data=X, columns=["X", "Y"]) cluster_df["cluster"] = [str(i) for i in y] @@ -97,6 +108,21 @@ app.layout = html.Div( children=[ html.Div( [ + dbc.Row( + [ + dbc.Col( + [ + dcc.Slider( + 1, + 10, + 1, + value=3, + id="slider_1", + ) + ] + ), + ] + ), dbc.Row( [ dbc.Col( @@ -106,7 +132,7 @@ app.layout = html.Div( [dcc.Graph(id="graph_4")], width=4 ), ] - ) + ), ], className="tab_content", ) @@ -143,8 +169,16 @@ def update_graph_2(min_value): Output("graph_3", "figure"), Output("graph_4", "figure"), Input("graph_3", "relayoutData"), + Input("slider_1", "value"), ) -def update_graph_3_and_4(selected_data): +def update_graph_3_and_4(selected_data, sliderValue): + # forcing update of x, y and cluster_df with the proper am + X, y = make_blobs( + n_samples=100 * sliderValue, centers=sliderValue, n_features=2, random_state=0 + ) + cluster_df = pd.DataFrame(data=X, columns=["X", "Y"]) + cluster_df["cluster"] = [str(i) for i in y] + if selected_data is None or ( isinstance(selected_data, dict) and "xaxis.range[0]" not in selected_data ): @@ -163,7 +197,7 @@ def update_graph_3_and_4(selected_data): y="Y", color="cluster", color_discrete_map=COLORS, - category_orders={"cluster": ["0", "1", "2"]}, + category_orders={"cluster": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]}, height=750, ) fig3.update_layout(template="plotly_white", coloraxis_showscale=False)