(Inspired by this stackoverflow question)
I would like to change the color of the bars, each time a button is clicked. It seems that the color of the bars just canβt be updated. Does anyone have a hint on this? (Code below)
dataset = pd.DataFrame(
{
"age": [19, 18, 28, 33, 32],
"bmi": [27.9, 33.77, 33.0, 22.705, 28.88],
"children": [0, 1, 3, 0, 0],
}
)
col_bins = {c: int(dataset[c].max() - dataset[c].min()) for c in dataset.columns}
fig = px.histogram(
x=dataset["age"], nbins=col_bins["age"], color_discrete_sequence=["darkred"]
)
fig.update_layout(
updatemenus=[
{
"buttons": [
{
"label": c,
"method": "update",
"args": [{"x": [dataset[c]], "nbinsx": bins}, {"xaxis.title": c}],
}
for c, bins in col_bins.items()
],
"direction": "right",
"type": "buttons",
"x": 1,
"y": 1.15,
}
],
xaxis_title="age",
title_text="Histograms",
)