Hello! I have a problem. I need to make a gantt chart as shown in this image:
Also, i need to implement a filtering system, like on this picture:
The filter selected in the dropdown menu is highlighted on the diagram, and the rest become transparent (keeping the color) . And all this should work through the callback.
Without thinking twice, I did the following:
@app.callback(
Output('timeline-output', 'figure'),
State('dropdown-input', 'value'),
Input('dropdown-button', 'n_clicks')
)
def graph_filtering(reason, click):
if reason:
if len(reason)>0:
filtered_df = df[df['reason'].isin(reason)]
fx1 = px.timeline(df,
x_start='state_begin',
x_end='state_end',
y='endpoint_name'
).update_layout(
xaxis={
'side':'top',
'dtick':3.6e+6,
'tickangle':0,
'tickformat':'%H'},
yaxis={
'dtick':3.6e+6,
'tickangle':0},
showlegend=False
).update_traces(
hovertemplate=None,
hoverinfo='skip')
fx2 = px.timeline(filtered_df,
x_start='state_begin',
x_end='state_end',
y='endpoint_name',
).update_layout(
xaxis={
'side':'top',
'dtick':3.6e+6,
'tickangle':0},
yaxis={
'dtick':3.6e+6,
'tickangle':0},
showlegend=False).
result_figure = make_subplots(specs=[[{'secondary_y':True}]])
result_figure.add_trace(
fx1.data[0],
secondary_y=False
)
result_figure.add_trace(
fx2.data[0],
secondary_y=True
)
result_figure.layout.xaxis = fx1.layout.xaxis
result_figure.data[0].opacity = 0.2
result_figure.update_layout(height=300, showlegend=False)
return result_figure
What i’am doing:
Having assigned the appropriate ids for callback (input, output) in app.layout, I created a function in which I created 2 figures and connected them using the make_subplots function, also set one of them to 0.2 opacity (to look like it should have been done initially)
At first glance, everything is fine and even filtering works, as described above (the selected filter is highlighted, and the rest become transparent). But as soon as I add to the parameters of px.timeline: color_discrete_map, color, something unimaginable begins to happen:
The diagram becomes like this:
As i delete or add filters, something starts to appear (with the right colors), but it does not work at all as it should.
I would like to attach two more screenshots that demonstrate what I say above and below, but I have a limit of 5
But if I return only 1 fig (fx1) in the function (and not make_subplots). In this case, the diagram correctly displays the colors.