Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Problem plotting a map


I’m trying to plot information on a map using Dash, but it’s behaving weirdly. When I try to filter the information using a dropdown, it doesn’t filter properly. I try this:

df = unexpected_events[unexpected_events['Participant'] == unexpected_participants]

But the output is an empty data frame, it won’t plot anything on the map, I tried to do an operation with one of the columns, and it gets mad…

Traceback (most recent call last):
  File "/path/lib/python3.6/site-packages/flask/", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/path/lib/python3.6/site-packages/flask/", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/path/lib/python3.6/site-packages/flask/", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/path/lib/python3.6/site-packages/flask/", line 33, in reraise
    raise value
  File "/path/lib/python3.6/site-packages/flask/", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/scrapworksinc/.virtualenvs/sw-ai/lib/python3.6/site-packages/flask/", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/path/lib/python3.6/site-packages/flask/", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/path/lib/python3.6/site-packages/flask/", line 33, in reraise
    raise value
  File "/path/lib/python3.6/site-packages/flask/", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/path/lib/python3.6/site-packages/flask/", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/path/lib/python3.6/site-packages/dash_auth/", line 35, in wrap
    response = f(*args, **kwargs)
  File "/path/lib/python3.6/site-packages/dash/", line 556, in dispatch
    return self.callback_map[target_id]['callback'](*args)
  File "/path/lib/python3.6/site-packages/dash/", line 513, in add_context
    output_value = func(*args, **kwargs)
  File "/path/", line 130, in unexpected_map
ValueError: max() arg is an empty sequence

As a sanity check, I use dash_table_experiments to create a table, and it works, then I tried to print the operation, and it works…

    dash.dependencies.Output('output-a', 'children'),
    [dash.dependencies.Input('unexpected_participants', 'value')])
def callback_a(unexpected_participants):
    df = unexpected_events[unexpected_events['Participant'] == unexpected_participants]
    return 'Your max number is "{}"'.format(max(df['HR']))

The callback for the map is:

    Output('unexpected_map', 'figure'), 
    [Input('unexpected_participants', 'value')])
def unexpected_map (unexpected_participants):
    df = unexpected_events[unexpected_events['Participant'] == unexpected_participants]

    data = [dict(
        type = 'scattergeo',
        locationmode = 'USA-states',
        lon = df['Longitude'],
        lat = df['Latitude'],
        mode = 'markers',
        marker = dict(
            size = 8,
            # cmax=max(df['HR']),
        name = 'HR')]

    layout = dict(
            title = 'Something',
            showlegend = True,
            geo = dict(
                projection=dict( type='albers usa' ),
                showland = True,
                landcolor = 'rgb(217, 217, 217)',
                subunitcolor="rgb(255, 255, 255)",
                countrycolor="rgb(255, 255, 255)"

    fig = dict( data=data, layout=layout )

    return {'data': data, 'layout': layout}

Am I missing something?