Hi guys,
Here is my dataframe:
import pandas as pd
df = pd.DataFrame({"Date":["2020-01-27","2020-02-27","2020-03-27","2020-04-27", "2020-05-27", "2020-06-27", "2020-07-27",
"2020-01-27","2020-02-27","2020-03-27","2020-04-27", "2020-05-27", "2020-06-27", "2020-07-27"],
"A_item":[2, 8, 0, 1, 8, 10, 4, 7, 2, 15, 5, 12, 10, 7],
"B_item":[1, 7, 10, 6, 5, 9, 2, 5, 6, 1, 2, 6, 15, 8],
"C_item":[9, 2, 9, 3, 9, 18, 7, 2, 8, 1, 2, 8, 1, 3],
"Channel_type":["Chanel_1", "Chanel_1", "Chanel_1", "Chanel_1", "Chanel_1", "Chanel_1", "Chanel_1",
"Chanel_2", "Chanel_2", "Chanel_2", "Chanel_2", "Chanel_2", "Chanel_2", "Chanel_2"]
})
I want to plot a group Bar chart with the dropdown filter on the Channel_type col. That’s what I am trying:
import plotly.express as px
fig = px.bar(df, x='Date', y=['A_item', 'B_item', 'C_item'])
fig.update_layout(barmode='group')
fig.show()
and here is the output:
However, that graph shows the aggregated data and what I am trying to achieve is to be able to filter it by the “Channel_type” column within a dropdown menu, while the layout of the group bar chart stays the same and all 3 item cols will be present for every dropdown option. The options for the dropdown to be:
Option 1: All (“Channel_1” & “Channel_2” - aggregated and same as the graph on my picture)
Option 2: “Channel_1” only
Option 3: “Channel_2” only
I was able to achieve it with the Ipython widgets, but for my specific task, I want it within the Plotly fig()
Any suggestions on how to accomplish that?
Thank you!