title: Efficient filtering of GeoJSON components with python dash-leaflet
body: <p>I'm using the Dash Leaflet map component <a href="https://github.com/thedirtyfew/dash-leaflet" rel="nofollow noreferrer">dash-leaflet</a>  for my interactive map visualizations.</p>
  <p>My goal is to filter large GeoJSON components (<code>dl.GeoJSON</code>) by values of dash components (e.g. <code>dcc.Slider</code>).</p>
  <p>My current approach is the following:</p>
  <pre><code>import random
  import dash
  import dash_html_components as html
  import dash_leaflet as dl
  import dash_leaflet.express as dlx
  import dash_core_components as dcc
  from dash.dependencies import Input, Output
  
  # Create some markers.
  points = [dict(lat=55.5 + random.random(), lon=9.5 + random.random(), value=random.random()*100) for i in range(100)]
  data = dlx.dicts_to_geojson(points)
  
  app = dash.Dash()
  app.layout = html.Div([
      dl.Map([
          dl.TileLayer(),
          dl.GeoJSON(id=&quot;data-id&quot;, data=data)
          ], center=(56, 10), zoom=8, style={'height': '50vh'}),
      html.Div([
          html.H5('Filtering'),
          dcc.Slider(id='my-slider', min=0, max=100, step=1, value=100),
          html.Div(id='slider-output-container')
          ], style={'width': '30%'}),
      ])
  
  @app.callback(
      Output('slider-output-container', 'children'),
      Output('data-id', 'data'),
      [Input('my-slider', 'value')])
  def update_output(value):
      points_new = [p for p in points if p['value'] &lt;= value]
      data_new = dlx.dicts_to_geojson(points_new)
      return 'You have selected value &quot;{}&quot;'.format(value), data_new
  
  if __name__ == '__main__':
      app.run_server()
  </code></pre>
  <p>In this example, the data object of the GeoJSON component &quot;data-id&quot; is filtered with the value of a dash component &quot;my-slider&quot; by filtering the list of points depending on the input value and returning a new geoJSON object created with the <code>dlx.dicts_to_geojson</code> function:</p>
  <pre><code>points_new = [p for p in points if p['value'] &lt;= value]
  data_new = dlx.dicts_to_geojson(points_new)
  </code></pre>
  <p>Is this the right way to filter a geoJSON object?</p>
  <p>I can imagine that there exists better ways to define such a filter function on the client side with the <code>options</code>-feature of the GeoJSON component and a javascript function but I don't know how.</p>
  <p>I appreciate any advice/code example I can get.</p>