Hi,
Your question is more related to filter in pandas right? If you want the dataframe where Area
is 1 or 2 and Anomalia
is 1, you can do something like:
idx = df["Area"].isin(area) & (df["Anomalia"] == int(anomalia))
Then use this boolean serie as indexer
X = df.loc[idx, "COORDENADA_X_PT"]
Y = df.loc[idx, "COORDENADA_Y_PT"]
If you want to include all anomalia, simply do something like:
if anomalia == "TD":
anomalia = [1,2]
else:
anomalia = [int(anomalia)]
idx = df["Area"].isin(area) & (df["Anomalia"].isin(anomalia))
So, if I sum up:
@app.callback(
Output(component_id='graph', component_property='children'),
[Input(component_id='filtro-area', component_property='value'),
Input(component_id='filtro-anomalia', component_property='value')]
)
def update_graph(area, anomalia):
if anomalia == "TD":
anomalia = [1,2]
else:
anomalia = [int(anomalia)]
idx = df["Area"].isin(area) & (df["Anomalia"].isin(anomalia))
return dcc.Graph(
id='example-graph',
animate=True,
figure={
'data': [
{
'x': df.loc[idx, 'COORDENADA_X_PT'], #X do poste
'y': df.loc[idx, 'COORDENADA_Y_PT'], #Y do poste
'type': 'scattergl',
'mode':'markers'
}
],
'layout': {
'hovermode':'closest', #Padrao closest
}
}
)
EDIT: I did not notice that your area
list is a list of string. You have better to let it as list of integer:
dcc.Dropdown(
id = 'filtro-area',
options=[
{'label': 'Área 1', 'value': 1},
{'label': 'Área 2', 'value': 2},
{'label': 'Área 3', 'value': 3}
],
multi=True,
value=[1, 2, 3],
placeholder = 'Selecione uma Área'
),