In mi code, when i push in dropdown with id which called ‘caracteristicas’, ‘update_sliders’ callback is activated. Why? WHat is wrong?
@app.callback(
[Output('table','data'),
Output('table','columns'),
Output('table','page_count')],
[Input('caracteristicas','value'),
Input('table', "page_current"),
Input('table', "page_size")])
def modify_table(carac,page_current,page_size):
print("1")
if carac:
columns=[{"name": x, "id": x} for x in carac]
df2 = data.loc[ : , carac]
df2 = df2.iloc[page_current*page_size:(page_current+ 1)*page_size
].to_dict('records')
lastCaracChoosen = carac.copy()
return df2,columns,math.ceil(len(data_aux)/page_size)
if carac == []:
lastCaracChoosen = carac.copy()
columns=[{"name": x, "id": x} for x in todosValores]
df2 = data.iloc[page_current*page_size:(page_current+ 1)*page_size
].to_dict('records')
return df2,columns,math.ceil(len(data_aux)/page_size)
@app.callback(
Output('sepallengthsepallength','children'),
[Input('filtrar','n_clicks')]
)
def update_sliders(n_clicks,):
print(n_clicks)
if n_clicks:
return u'sepallength ({} - {})'.format(n_clicks,n_clicks)
@app.callback(
Output('slider-container','children'),
[Input('caracteristicas','value')],
[State('slider-container','children')])
def init_sliders(valores,existing_sliders):
print("2")
if existing_sliders:
#Se ha quitado un valor
difference = list(set(lastCaracChoosen) - set(valores))
if difference:
for i in difference:
index = todosValores.index(i)
existing_sliders[index]['props']['style']['display'] = "{}".format(None)
## Resetear rangeslider cuando se quita
if (data[i].dtype == "int64" or data[i].dtype == "float64" and (len(data[i].unique())) > 10):
existing_sliders[index]['props']['children'][0]['props']['children'][1]['props']['value'] = \
[existing_sliders[index]['props']['children'][0]['props']['children'][1]['props']['min'],
existing_sliders[index]['props']['children'][0]['props']['children'][1]['props']['max']]
else:
## Resetear dropdown cuando se quita
existing_sliders[index]['props']['children'][0]['props']['children'][1]['props']['value'] = []
return existing_sliders
else:
#Se ha sumado un valor
difference = list(set(valores) - set(lastCaracChoosen))
for i in difference:
index = todosValores.index(i)
existing_sliders[index]['props']['style']['display'] = "block"
return existing_sliders
else:
for i in todosValores:
if (data[i].dtype == "int64" or data[i].dtype == "float64" and (len(data[i].unique())) > 10):
existing_sliders.append(html.Div([
dbc.FormGroup(
[
#dbc.Label(children='{} ({} - {})'.format(i,min(data[i]),max(data[i])),id='{}{}'.format(i,i)),
html.Div(children='{} ({} - {})'.format(i,min(data[i]),max(data[i])),id='{}{}'.format(i,i)),
dcc.RangeSlider(
id='{}'.format(i),
min=min(data[i]),
max=max(data[i]),
step=round((max(data[i])-min(data[i]))/100,2),
value=[min(data[i]),max(data[i])],
#updatemode='drag',
allowCross=False,
marks={
min(data[i]): {'label': '{}'.format(min(data[i]))},
max(data[i]): {'label': '{}'.format(max(data[i]))}
},
)
]),
],className='col',style={'marginLeft': 0, 'marginRight': 0, 'marginTop': 0, 'marginBottom': 10,
'backgroundColor':'#F7FBFE',
'border': 'thin lightgrey dashed',
'border-radius': 10,
'width':'auto',
'display': '{}'.format(None),
'padding': '6px 4px 4px 8px'}))
else:
existing_sliders.append(html.Div([
dbc.FormGroup(
[
#dbc.Label(children='{}'.format(i),id='{}{}'.format(i,i)),
html.Div(children='{}'.format(i),id='{}{}'.format(i,i)),
dcc.Dropdown(
id = '{}'.format(i),
options = [{
'label' : x,
'value' : x
}for x in data[i].unique()],
multi = True,
placeholder=i
)
])
],className='col',style={'marginLeft': 0, 'marginRight': 0, 'marginTop': 0, 'marginBottom': 10,
'backgroundColor':'#F7FBFE',
'border': 'thin lightgrey dashed',
'border-radius': 10,
'width':'auto',
'display': '{}'.format(None),
'padding': '6px 4px 4px 8px'}))
return existing_sliders```