I need to get the name of the columns of the dataframe and apply in a Dropdown id=‘check_opcao’ to be able to select. and then in the callback function I need to filter the dataframe to select only the columns where it corresponds to the value I selected in the Dropdown
I tried a way where I created a new column in df called (Options) colunas = ['Player','Rnd','ACS','K:D','KAST','ADR','KPR','APR','FKPR','FDPR','HS%','CL%','CL','KMax','K','D','A','FK','FD','Team'] df['Colunas'] = pd.Series(colunas)
and added the values with the names of each column but when I try to filter tabela_filtrada = df.loc[df['Colunas'] == check_opcao,:]
it returns only the rows that correspond to my selection in the dropdown…
colunas = ['Player','Rnd','ACS','K:D','KAST','ADR','KPR','APR','FKPR','FDPR','HS%','CL%','CL','KMax','K','D','A','FK','FD','Team']
df['Colunas'] = pd.Series(colunas)
fig = px.bar(df, x='Player', y='ACS', title='Top 10 jogadoras com o maior ACS no Game Changers Brasil:', color='Player', barmode = 'stack',
labels={
'Player': 'Nome e Time',
'ACS': 'ACS'}, template='plotly_dark', text='ACS')
opcoes = list(df['Colunas'].unique())
app.layout = html.Div(children=[
html.H5('Opcões'),
dcc.Dropdown(opcoes, value = 'ACS' , id='check_opcao'),
dcc.Graph(figure=fig, id='grafico_gc_players')
])
@app.callback(
Output('grafico_gc_players', 'figure'),
[
Input('check_opcao', 'value'),
])
def renderizar_graficos(check_opcao):
if check_opcao == 'ACS':
fig = px.bar(df, x='Player', y='ACS', color='Player', barmode = 'stack',
labels={
'Player': 'Nome e Time'}, template='plotly_dark')
else:
tabela_filtrada = df.loc[df['Colunas'] == check_opcao,:]
fig = px.bar(tabela_filtrada, x='Player', y= check_opcao, color='Player', barmode = 'stack',
labels={
'Player': 'Nome e Time'}, template='plotly_dark')
return fig