Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

Basic Dash (python) question about passing DCC value to a graph

So, I think this is probably more of a python syntax question but, the context of dash so, hopefully someone smarter than me (most people here I’m sure) will have a quick answer.

I have a dropdown component. When the user chooses a value, it will correspond to a a column in my dataframe that I want to show on the X axis of my bar graph.

I’ve tried a few ways to do this but, can’t figure it out. None of these approaches seem to work:
Where ‘value_metric’ is my component id of the dropdown.

dff = df[df.Player_SK == value_player]

fig = px.bar(data_frame=dff, x=‘Game_SK’, y=[{‘value_metric’:‘value’}])
or
fig = px.bar(data_frame=dff, x=‘Game_SK’, y={value_metric:‘value’})
or
a few others…

Thank you in advance and I hope my question was clear.

Hi @pawlowski6132!

I am not sure I understand what you did. Is this inside a callback?

It should look more or less like this:

@app.callback(
    Output('graph', 'figure'),  # from dcc.Graph(id="graph")
    Input('value_metric', 'value)
)
def update_graph(value_metric):
     # value_metric is the value selected in Dropdown
    fig = px.bar(ddff, x='Game_SK', y=value_metric)
    return fig

Perfect. Thanxc so much.

1 Like