Hi community!
I’ve been scratching my head on this for ages - I am looking to allow users to click a team logo to filter a table that shows players in that team.
This is my app.layout:
def update_layout():
data = getShots(None)
return html.Div(children=[
html.Div(
html.Div(
[html.A(
html.Img(src=teams.loc[teams['TeamID'] == i, 'TeamLogo'].iloc[0], style={'height': '92px'}, className='team-overlay', id='team-logo-'+str(i)))
for i in teams['TeamID'].values if i is not None],
), className='team-container'),
html.Div(id="placeholder"),
html.Div(
get_data_object(teamdf), id='tableContainer')
])
app.layout = update_layout()
And this is my callback:
@app.callback(
Output('tableContainer', 'children'),
[
# there are 30 team images
Input('team-logo-1610612737', 'n_clicks'), Input('team-logo-1610612737', 'src'),
Input('team-logo-1610612738', 'n_clicks'), Input('team-logo-1610612738', 'src'),
...
...
...
# Input('team-logo-1610612766', 'n_clicks'), Input('team-logo-1610612766', 'src'),
])
def update_graph(n_clicks1, src1, n_clicks2, src2... n_clicksN, scrN):
if n_clicks1:
teamId = teams.loc[teams['TeamLogo'] == src1, 'TeamID'].iloc[0]
if n_clicks2:
teamId = teams.loc[teams['TeamLogo'] == src2, 'TeamID'].iloc[0]
else:
teamId = None
teamdf = parseTeams(rosters, teamId)
return get_data_object(teamdf)
This is sort of something but I don’t think the solution is 30 separate n_clicks and src Inputs in the callback function.
Is there away for me to use the Outer Div element and then use the html.Img that I click and then pass the src to get the TeamId.
Any help would be appreciated!
Pratik