# selectData doesnt worth with large datasets

**URL:** <https://community.plotly.com/t/selectdata-doesnt-worth-with-large-datasets/6229>\
**Category:** Dash Python\
**Created:** [October 11, 2017, 6:31pm UTC](https://community.plotly.com/t/selectdata-doesnt-worth-with-large-datasets/6229 "2017-10-11T18:31:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilovecheese](https://avatars.discourse-cdn.com/v4/letter/i/34f0e0/32.png) [@ilovecheese](https://community.plotly.com/u/ilovecheese)\
**Post date:** [October 11, 2017, 6:31pm UTC](https://community.plotly.com/t/selectdata-doesnt-worth-with-large-datasets/6229/1 "2017-10-11T18:31:53Z")

</div>

I am trying to use the boxSelect tool with lines in order feed a callback the range selected. Unfortunately, the boxSelect tool doesnt even show up with lines so I had to add 2 points of a scatterplot just to see it. Once I got around that, I saw that the callback wouldnt activate. After hours if trying to identify the problem, I realized that boxselect only works when there are a small amount of points on the graph. If this exceeds a pretty small value (in my case even 100 points), the selectValue callback no longer does anything.

See this code:

```
import numpy as np

# plotting imports
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import plotly.graph_objs as go

app = dash.Dash()
app.config.supress_callback_exceptions = True

plot1 = dcc.Graph(id='plot1')
plot2 = dcc.Graph(id='plot2')

N=100
plot1_data = [{'x': np.random.rand(N),
               'y': np.random.rand(N),
               'name': 'line',
               },
              {'x': [0, 1, 2],
                 'y': [0, 1, 0],
                 'mode': 'markers',
                 'marker': {'size': 10},
                 'name': 'scatter'
                 },
              ]
plot1_fig = {
        'data': plot1_data,
        'layout': go.Layout(
            hovermode='closest'
        )
    }
plot1.figure=plot1_fig

app.layout = html.Div([plot1, plot2], style={'width': '100%'})

@app.callback(
    Output('plot2', 'figure'),
    [Input('plot1', 'selectedData')])
def update_plot2(some_input):
    print('callback activated')
    x = np.random.rand(10)
    y = np.random.rand(10)
    plot2_data = [{'x': x,
                   'y': y,
                   'mode': 'markers',
                   'marker': {'size': 10}
                   }]
    plot2_fig = {
        'data': plot2_data,
        'layout': go.Layout(
            hovermode='closest'
        )
    }
    return plot2_fig

if __name__ == ' __main__':
    app.run_server()

```

If N=10, the code works fine.

I have a few questions:

1. This feature of boxselect / selectData callback should be documented and a warning should show up
2. How can I enable the functionality I want, which is to select a portion of the graph and send the ranges selected (not the points) to a callback. I know I can use the zoom relayoutData callback, but i specifically dont want the graph to change or zoom in.

---

<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:** [October 11, 2017, 7:02pm UTC](https://community.plotly.com/t/selectdata-doesnt-worth-with-large-datasets/6229/2 "2017-10-11T19:02:23Z")

</div>

> [@ilovecheese](#):
>
> Unfortunately, the boxSelect tool doesnt even show up with lines

Thanks for reporting! We’re working on this issue and tracking it in [Lasso and select-box support for traces other than scatter marker and scatter text · Issue #170 · plotly/plotly.js · GitHub](https://github.com/plotly/plotly.js/issues/170).

> [@ilovecheese](#):
>
> This feature of boxselect / selectData callback should be documented

Yeah, that’s a good idea. We can add it here: [dash-docs/tutorial/graphing.py at 03c58ceaea700012485ede6aa58325cbf12f596a · plotly/dash-docs · GitHub](https://github.com/plotly/dash-docs/blob/03c58ceaea700012485ede6aa58325cbf12f596a/tutorial/graphing.py#L103)

> [@ilovecheese](#):
>
> How can I enable the functionality I want, which is to select a portion of the graph and send the ranges selected (not the points) to a callback.

It’s not possible to ignore part of the `selectedData` object, but that’s a good idea. We could make it a property of `dcc.Graph`.

> [@ilovecheese](#):
>
> If this exceeds a pretty small value (in my case even 100 points), the selectValue callback no longer does anything.

Thanks for reporting! Sounds like a bug. However, I can’t reproduce it. Here’s the example that I tried which displays the number of points in the `selectedData` object:

 ![dash-select-large-data](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/c/c58af3550673c87745f71b288dcef541b6d711ae.gif)

```auto
import numpy as np

# plotting imports
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import plotly.graph_objs as go

app = dash.Dash()

N = 1000

app.layout = html.Div([
    html.Div(id='output'),
    dcc.Graph(
        id='plot',
        figure={
            'data': [{
                'x': np.random.randn(N),
                'y': np.random.randn(N),
                'mode': 'markers'
            }]
        },
        selectedData={
            'points': []
        }
    )
], style={'width': '100%'})

@app.callback(
    Output('output', 'children'),
    [Input('plot', 'selectedData')])
def display_points(selectedData):
    return 'You have selected {} points'.format(
        len(selectedData['points']))

if __name__ == ' __main__':
    app.run_server(debug=True)

```

* * *

Finally, if any company out there would like to help prioritize this work through a sponsorship, please reach out: [Consulting, Training & Open-Source Development](https://plot.ly/products/consulting-and-oem/)

---

<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:** [December 7, 2017, 10:47pm UTC](https://community.plotly.com/t/selectdata-doesnt-worth-with-large-datasets/6229/3 "2017-12-07T22:47:40Z")

</div>

Split this topic on December 7, 2017, 10:47pm UTC

A post was split to a new topic: [Issue with `selectedData`](https://community.plotly.com/t/issue-with-selecteddata/7208)
