# Select-data from callback generated graph dash

**URL:** <https://community.plotly.com/t/select-data-from-callback-generated-graph-dash/41763>\
**Category:** Dash Python\
**Created:** [June 30, 2020, 3:27am UTC](https://community.plotly.com/t/select-data-from-callback-generated-graph-dash/41763 "2020-06-30T03:27:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cocainesteamedrice](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@cocainesteamedrice](https://community.plotly.com/u/cocainesteamedrice)\
**Post date:** [June 30, 2020, 3:27am UTC](https://community.plotly.com/t/select-data-from-callback-generated-graph-dash/41763/1 "2020-06-30T03:27:04Z")

</div>

Hellow, I am trying to create a graph via a dash app callback from selected data (lasso or box) from another graph that I have created from the first dash app callback.

The first dash app callback output graph component property is children as such:

```auto
@app.callback(	
    Output(component_id='firstgraph', component_property='children'),	
    [Input(component_id='firstgraphinput1', component_property='value'),
    Input(component_id='firstgraphinput2', component_property='value')]	
)

```

So when I try to select data from this graph, the callback does not work, because the component\_property cannot be “selectedData”)… as such:

```auto
@app.callback(	
    Output("selected-data", "figure"),	
    [	
        Input("firstgraph", "selectedData"),	
    ]	
)

```

I get a an error message along the lines of: “selectedData is not a valid component property”

In Summary I am trying to figure out how to select data from the first generated graph via the first callback, and create a summary of the selected data.

I hope this was clear, if not I will do my best to elaborate.

Thank you!

---

<div class="post-metadata">

**Author:** ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)\
**Post date:** [June 30, 2020, 4:21am UTC](https://community.plotly.com/t/select-data-from-callback-generated-graph-dash/41763/2 "2020-06-30T04:21:11Z")

</div>

> [@cocainesteamedrice](#):
>
> “selectedData is not a valid component property”

are you sure that the firstgraph is part of the dcc.Graph component and not some other component?

---

<div class="post-metadata">

**Author:** ![cocainesteamedrice](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@cocainesteamedrice](https://community.plotly.com/u/cocainesteamedrice)\
**Post date:** [June 30, 2020, 2:13pm UTC](https://community.plotly.com/t/select-data-from-callback-generated-graph-dash/41763/3 "2020-06-30T14:13:24Z")

</div>

Hi ChriddyP thanks for your reply.

This is the App callback and code that generates the chart… and here it is in the APP layout:

```auto
@app.callback(	
    Output(component_id='firstgraph', component_property='children'),	
    [Input(component_id='firstgraphinput1', component_property='value'),
    Input(component_id='firstgraphinput2', component_property='value')]	
)		
def update_valuecb(input_data,input_data2):	

        
    figbt = px.scatter(x=btdf[input_data], y=btdf[input_data2],opacity=0.35)
    figbt.update_layout(shapes=[
        dict(
          type= 'line',
          yref= 'paper', y0= 0, y1= 1,
          xref= 'x', x0= btdf[input_data].iloc[-1],x1= btdf[input_data].iloc[-1]
        )
    ])
    figbt.layout.plot_bgcolor='#1E2130'	
    figbt.layout.paper_bgcolor = '#1E2130'
    figbt.update_layout(xaxis = {                                     	
                                    'showgrid': False	
                                         },	
                                yaxis = {                              	
                                   'showgrid': False},	
            title={	
            'text': str(input_data)+" Day Correlation Backtest",	
            'y':0.9,	
            'x':0.4,	
            'xanchor': 'center',	
            'yanchor': 'top'},	
        yaxis_title=str(input_data)+" Day % Return",	
        xaxis_title=str(input_data)+" Day Sector Correlation",	
        font=dict(	
            family="Courier New, monospace",	
            size=18,	
            color="white"	
        )	
    )	

    return dcc.Graph(style={'height': '700px'},figure=figbt)

```

```auto
                html.Div(children=[	
            html.Div(children='''	
                Select Correlation Lookback From Dropdown:	
            ''',style= {"color":"aquamarine","background-color":'#1E2130'}),	
            dcc.Dropdown(options=dropdownlistc,id='firstgraphinput1',value=10),
            '''	
                Select Forward Return Period From Dropdown:	
            ''',
            dcc.Dropdown(options=dropdownlistcd,id='firstgraphinput2',value='r1'),
                        html.Div(id='firstgraph'),	
	])

```

Does this help answer your question?

Thanks.

---

<div class="post-metadata">

**Author:** ![mbkupfer](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/mbkupfer/32/4334_2.png) [@mbkupfer](https://community.plotly.com/u/mbkupfer)\
**Post date:** [June 30, 2020, 2:27pm UTC](https://community.plotly.com/t/select-data-from-callback-generated-graph-dash/41763/4 "2020-06-30T14:27:34Z")

</div>

The div has the graph id in this case.

Your graph generating callback should add the id to the graph being returned.

```auto
return dcc.Graph(id="first graph", style={'height': '700px'},figure=figbt)

```

---

<div class="post-metadata">

**Author:** ![cocainesteamedrice](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@cocainesteamedrice](https://community.plotly.com/u/cocainesteamedrice)\
**Post date:** [July 1, 2020, 2:00am UTC](https://community.plotly.com/t/select-data-from-callback-generated-graph-dash/41763/5 "2020-07-01T02:00:48Z")

</div>

Hi thanks for your reply. I added that in and still got the following error:

```auto
Attempting to assign a callback with
the property "selectedData" but the component
"firstgraph" doesn't have "selectedData" as a property.

Here are the available properties in "firstgraph":
['children', 'id', 'n_clicks', 'n_clicks_timestamp', 'key', 'role', 'data-*', 'aria-*', 'accessKey', 'className', 'contentEditable', 'contextMenu', 'dir', 'draggable', 'hidden', 'lang', 'spellCheck', 'style', 'tabIndex', 'title', 'loading_state']

```

Thank you

---

<div class="post-metadata">

**Author:** ![adamschroeder](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adamschroeder/32/17280_2.png) [@adamschroeder](https://community.plotly.com/u/adamschroeder)\
**Post date:** [July 1, 2020, 12:41pm UTC](https://community.plotly.com/t/select-data-from-callback-generated-graph-dash/41763/6 "2020-07-01T12:41:16Z")

</div>

Hi @cocainesteamedrice,  
What @mbkupfer way trying to say is that you’re dcc.Graph() needs an id that you can refer to in the input.  
Right now “firstgraph” is the id of the HTML.div(). And a Div does not have a Selectdata property. You need to give you dcc.graph a unique id
