🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

Filtering in Gantt-Chart not working

I have been working on a Gantt-Chart which can be filtered, so it only shows Job who are actually selected.

Here is the code

import dash
import dash_html_components as html
import dash_core_components as dcc
import plotly.plotly as py
import plotly.graph_objs as go
import psycopg2 as pg
import pandas.io.sql as psql
import pandas as pd
import numpy as np
import plotly.figure_factory as ff
from dash.dependencies import Input, Output, Event, State
from dash.exceptions import PreventUpdate
from datetime import datetime as dt

df = [dict(Task=“Job-1”, Start=‘2017-01-01’, Finish=‘2017-02-02’, Resource=‘Realizado’),
dict(Task=“Job-1”, Start=‘2017-02-15’, Finish=‘2017-03-15’, Resource=‘Incumplimiento’),
dict(Task=“Job-2”, Start=‘2017-01-17’, Finish=‘2017-02-17’, Resource=‘Programado’),
dict(Task=“Job-2”, Start=‘2017-01-17’, Finish=‘2017-02-17’, Resource=‘Realizado’),
dict(Task=“Job-3”, Start=‘2017-03-10’, Finish=‘2017-03-20’, Resource=‘Programado’),
dict(Task=“Job-3”, Start=‘2017-04-01’, Finish=‘2017-04-20’, Resource=‘Programado’),
dict(Task=“Job-3”, Start=‘2017-05-18’, Finish=‘2017-06-18’, Resource=‘Programado’),
dict(Task=“Job-4”, Start=‘2017-01-14’, Finish=‘2017-03-14’, Resource=‘Realizado’)]
df= pd.DataFrame(df)

colors = {‘Programado’: ‘rgb(220, 0, 0)’,
‘Incumplimiento’: (1, 0.9, 0.16),
‘Realizado’: ‘rgb(0, 255, 100)’}

app = dash.Dash()

app.layout = html.Div([
options=[{‘label’: i, ‘value’: i} for i in df[‘Task’].unique()],
options=[{‘label’: ‘Seleccionar todos’, ‘value’: 1}], values=[1])
], id=‘checklist-container’,

#Interactividad con gantt
[dash.dependencies.Input(‘dropdown’, ‘value’)])
def update_output_estado(value):
df2=df[(df[‘Task’].isin(value))]#filtro de tipo de Actividades
fig = ff.create_gantt(df2, colors=colors, index_col=‘Resource’, show_colorbar=True, group_tasks=True, title=‘Calendario’)
return fig

#Menú de selección
Output(‘dropdown’, ‘value’),
[Input(‘select-all’, ‘values’)],
[State(‘dropdown’, ‘options’)])
def test(selected, options):
if len(selected) > 0:
return [i[‘value’] for i in options]
raise PreventUpdate()


The point here is that I am receiving the following error


[2019-01-31 09:25:47,635] ERROR in app: Exception on /_dash-update-component [POST]
Traceback (most recent call last):
File “C:\Python372\lib\site-packages\flask\app.py”, line 1982, in wsgi_app
response = self.full_dispatch_request()
File “C:\Python372\lib\site-packages\flask\app.py”, line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File “C:\Python372\lib\site-packages\flask\app.py”, line 1517, in handle_user_exception

reraise(exc_type, exc_value, tb)

File “C:\Python372\lib\site-packages\flask_compat.py”, line 33, in reraise
raise value
File “C:\Python372\lib\site-packages\flask\app.py”, line 1612, in full_dispatch_request
rv = self.dispatch_request()
File “C:\Python372\lib\site-packages\flask\app.py”, line 1598, in dispatch_request
return self.view_functionsrule.endpoint
File “C:\Python372\lib\site-packages\dash\dash.py”, line 967, in dispatch
return self.callback_map[target_id]‘callback’
File “C:\Python372\lib\site-packages\dash\dash.py”, line 907, in add_context
output_value = func(*args, **kwargs)
File “gant-chart_DASHBOARD_almostworking.py”, line 55, in update_output_estado
fig = ff.create_gantt(df2, colors=colors, index_col=‘Resource’, show_colorbar=True, group_tasks=True, title=‘Calendario’)
File “C:\Python372\lib\site-packages\plotly\figure_factory_gantt.py”, line 732, in create_gantt
if index_col not in chart[0]: