This is my code it compiles well and when I do the filters through the multi dropdown it works fine, the problem is when I remove all the filters the graphics are empty
app = dash.Dash(__name__)
cantid = len(df.index)
tipopersonal = df['Tipopersonal'].unique()
app.layout = html.Div(children=[
html.Div(children=[
html.Label('ANALISIS DE REINGRESOS CON CONSUMO MENOR AL 50%',style={'width': '100%', 'display': 'inline-block','text-align':'center'}),
html.Label('Seleccione tipo de personal'),
dcc.Dropdown(
options=[{'label':x, 'value':x} for x in aaa6['Tipopersonal'].unique()],
#value=[options],
multi=True,
searchable=True,
clearable=False,
id='dtipopersonal'
)], style={'width': '33%', 'display': 'inline-block'}),
html.Div(children=[
html.Label('Seleccione Motivo'),
dcc.Dropdown(
options=[{'label':h, 'value':h} for h in aaa6['Motivo'].unique()],
multi=True,
searchable=True,
#persistence = True,
#value=[lista]
#clearable = True ,
id='motiv'
)], style={'width': '33%', 'display': 'inline-block'}),
html.Div(children=[
html.Label('Seleccione centro de costo'),
dcc.Dropdown(
options=[{'label':c, 'value':c} for c in aaa6['Ncc'].unique()],
multi=True,
searchable=True,
#value: allID',
#persistence = True,
#value=[lista]
#clearable = True ,
id='dd_centroc'
)], style={'width': '33%', 'display': 'inline-block'}),
html.Div(children=[
html.Label('Seleccione bodega'),
dcc.Dropdown(
options=[{'label':l, 'value':l} for l in aaa6['Nombre Bodega'].unique()],
multi=True,
searchable=True,
id='bode'
)], style={'width': '50%', 'display': 'inline-block'}), #allow multiple dropdown values to be selecte
html.Div(children=[
html.Label('Seleccione material'),
dcc.Dropdown(
options=[{'label':m, 'value':m} for m in aaa6['Descripcion'].unique()],
multi=True,
searchable=True,
id='mate'
)], style={'width': '50%', 'display': 'inline-block'}),
html.Div(children=[
html.Label('Seleccione nombre de personal'),
dcc.Dropdown(
options=[{'label':t, 'value':t} for t in aaa6['Nombreentrega'].unique()],
multi=True,
searchable=True,
id='entre'
)], style={'width': '50%', 'display': 'inline-block'}),
html.Div(children=[
html.Label('Seleccione fecha de inicio'),
dcc.Dropdown(
options=[{'label':t, 'value':t} for t in fech['nombre'].unique()],
multi=True,
searchable=True,
id='feini'
)], style={'width': '25%', 'display': 'inline-block'}),
html.Div(children=[
html.Label('Seleccione fecha de fin'),
dcc.Dropdown(
options=[{'label':t, 'value':t} for t in fech['nombre'].unique()],
multi=True,
searchable=True,
id='fefin'
)], style={'width': '25%', 'display': 'inline-block'}),
html.Label(f'Cantidad de transacciones {cantid} ',style={'width': '100%', 'display': 'inline-block'}),
dcc.Graph(id='motix',figure = px.pie(aaa6, values='cantidadreingresada' , names='Motivo', title='Motivos de reingresos'),style={'width': '35%', 'display': 'inline-block'}),##figure=px.pie(aaa6, values='cantidadreingresada' , names='Motivo', title='Motivo'),style={'width': '100%', 'display': 'inline-block'},
dcc.Graph(id='areasgraf',figure=px.bar(nccn, x=ccn, y=ccc, title='Reingresos por centro de costo'),style={'width': '65%', 'display': 'inline-block'}),
dcc.Graph(id='person',figure=px.bar(nen, x="Nombreentrega", y="nombre", title='Personal que mas reingresa'),style={'width': '50%', 'display': 'inline-block'}),
#dcc.Graph(id='materia',figure = px.pie(mater, values='Descripcion' , names='nombre', title='Materiales mas reingresados'),style={'width': '100%', 'display': 'inline-block'}),##figure=px.pie(aaa6, values='cantidadreingresada' , names='Motivo', title='Motivo'),style={'width': '100%', 'display': 'inline-block'},
dcc.Graph(id='materia',figure = px.bar(y=xmatecant, x=xmatedesc, text_auto='.2s',title="Material mas retenido por unidad de medida"),style={'width': '50%', 'display': 'inline-block'}),
dcc.Graph(id='lin',figure = px.line(x=desfe, y=canfe, title='Fechas con mas reingresos'),style={'width': '100%', 'display': 'inline-block'}),
dcc.Graph(id='bodeanima',figure = px.bar(aaa6, x="Nombre Bodega", y="cantidadreingresada", color="Descripcion",animation_frame="fechareingreso", animation_group="Descripcion")),
#dcc.Graph(id='lin2',figure =px.scatter(aaa6, x="cantidadreingresada", y="GrupoTemporalidad", animation_frame="fechareingreso", animation_group="Nombreentrega",
#size="Temporalidad", color="Ncc", hover_name="Descripcion"))
#dcc.Graph(id='tempo',figure=px.pie(aaa3, values='cantidadreingresada' , names='GrupoTemporalidad', title='Temporalidad'),style={'width': '44%', 'display': 'inline-block'}),#
]
)
#aqui irian los callbacks
@app.callback(
Output('motix','figure'),
Input('motiv','value'),Input('dd_centroc','value'),Input('dtipopersonal','value'),Input('mate','value'),Input('entre','value'),Input('bode','value'), prevent_initial_call=True
)
def build_graph(motiv,dd_centroc,dtipopersonal,mate,entre,bode):
new_df=df
if motiv is None and dd_centroc is None and dtipopersonal is None and mate is None and entre is None and bode is None :
return figure
if motiv != None:
new_df=new_df[(new_df['Motivo'].isin(motiv))]
if dd_centroc != None:
new_df=new_df[(new_df['Ncc'].isin(dd_centroc))]
if dtipopersonal != None:
new_df=new_df[(new_df['Tipopersonal'].isin(dtipopersonal))]
if mate != None:
new_df=new_df[(new_df['Descripcion'].isin(mate))]
if entre != None:
new_df=new_df[(new_df['Nombreentrega'].isin(entre))]
if bode != None:
new_df=new_df[(new_df['Nombre Bodega'].isin(bode))]
new_df = new_df.sort_values('cantidadreingresada')
fig_fil1 = (px.pie(new_df, values='cantidadreingresada' , names='Motivo', title='Motivos de reingreso'))
return fig_fil1
@app.callback(
Output('areasgraf','figure'),
Input('motiv','value'),Input('dd_centroc','value'),Input('dtipopersonal','value'),Input('mate','value'),Input('entre','value'),Input('bode','value'), prevent_initial_call=True
)
def build_graph2(motiv,dd_centroc,dtipopersonal,mate,entre,bode):
new_df=df
if motiv is None and dd_centroc is None and dtipopersonal is None and mate is None and entre is None and bode is None :
return figure
if motiv != None:
new_df=new_df[(new_df['Motivo'].isin(motiv))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if dd_centroc != None:
new_df=new_df[(new_df['Ncc'].isin(dd_centroc))]
new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if dtipopersonal != None:
new_df=new_df[(new_df['Tipopersonal'].isin(dtipopersonal))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if mate != None:
new_df=new_df[(new_df['Descripcion'].isin(mate))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if entre != None:
new_df=new_df[(new_df['Nombreentrega'].isin(entre))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if bode != None:
new_df=new_df[(new_df['Nombre Bodega'].isin(bode))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
new_df = new_df.sort_values('cantidadreingresada')
figure223=px.bar(new_df, x="Ncc", y="cantidadreingresada", title='Centro de costo')
return figure223
@app.callback(
Output('person','figure'),
Input('motiv','value'),Input('dd_centroc','value'),Input('dtipopersonal','value'),Input('mate','value'),Input('entre','value'),Input('bode','value'), prevent_initial_call=True
)
def build_graph2(motiv,dd_centroc,dtipopersonal,mate,entre,bode):
new_df=df
if motiv is None and dd_centroc is None and dtipopersonal is None and mate is None and entre is None and bode is None :
return figure
if motiv != None:
new_df=new_df[(new_df['Motivo'].isin(motiv))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if dd_centroc != None:
new_df=new_df[(new_df['Ncc'].isin(dd_centroc))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if dtipopersonal != None:
new_df=new_df[(new_df['Tipopersonal'].isin(dtipopersonal))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if mate != None:
new_df=new_df[(new_df['Descripcion'].isin(mate))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if entre != None:
new_df=new_df[(new_df['Nombreentrega'].isin(entre))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if bode != None:
new_df=new_df[(new_df['Nombre Bodega'].isin(bode))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
new_df = new_df.sort_values('cantidadreingresada')
figure222=px.bar(new_df, x="Nombreentrega", y="cantidadreingresada", color="Nombreentrega", title='Personal que mas reingresa')
return figure222
@app.callback(
Output('materia','figure'),
Input('motiv','value'),Input('dd_centroc','value'),Input('dtipopersonal','value'),Input('mate','value'),Input('entre','value'),Input('bode','value'), prevent_initial_call=True
)
def build_graph32(motiv,dd_centroc,dtipopersonal,mate,entre,bode):
new_df=df
if motiv is None and dd_centroc is None and dtipopersonal is None and mate is None and entre is None and bode is None :
return figure
if motiv != None:
new_df=new_df[(new_df['Motivo'].isin(motiv))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if dd_centroc != None:
new_df=new_df[(new_df['Ncc'].isin(dd_centroc))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if dtipopersonal != None:
new_df=new_df[(new_df['Tipopersonal'].isin(dtipopersonal))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if mate != None:
new_df=new_df[(new_df['Descripcion'].isin(mate))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if entre != None:
new_df=new_df[(new_df['Nombreentrega'].isin(entre))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
if bode != None:
new_df=new_df[(new_df['Nombre Bodega'].isin(bode))]
#new_df = new_df.sort_values('cantidadreingresada')
#new_df=new_df.head(10)
new_df = new_df.sort_values('cantidadreingresada')
dfxmate2 = new_df. groupby (['Descripcion'] ).cantidadreingresada.sum().sort_values(ascending = False)
dfxmate2 = dfxmate.to_frame()
dfxmate2['Descripcion'] = dfxmate.index
dfxmate2=dfxmate2.head(15)
xmatecant2 = dfxmate2['cantidadreingresada'].tolist()
xmatedesc2= dfxmate2['Descripcion'].tolist()
figure2252 = px.bar(y=xmatecant2, x=xmatedesc2, text_auto='.2s',title="Material mas retenido por unidad de medida_"),
return figure2252
#if dd_centroc is None:
#return fig
#else:
#new_df1=new_df[(new_df['Ncc'].isin(dd_centroc))]
#fig_fil1 = (px.pie(new_df1, values='cantidadreingresada' , names='Motivo', title='5555555555555'))
#return fig_fil2
#new_df = aaa6[(aaa6['Ncc'].isin(dd_centroc))]
#ejecutamos el dash
if __name__ == '__main__':
app.run_server(debug=False, port=8003)