Hi all. I am having an issue using a pandas series as the input for marker color in my go.scattermapbox. The error occurred when I subsetted my data using pandas to create a more limited input csv.
Original Case:
def update_figure(chosen_dist):
print("Chosen: ", chosen_dist)
intersections_sub = intersections[(intersections['name'].isin(chosen_dist))]
print(intersections_sub)
print(intersections_sub['Color Map'])
## Create figure
locations=[go.Scattermapbox(
lon = intersections_sub['Long'],
lat = intersections_sub['Lat'],
mode = 'markers',
marker={'color': intersections_sub['Color Map'], 'opacity' : 0.30, 'size': 15},
unselected={'marker': {'opacity': 0.20, 'size' : 15}},
selected={'marker': {'opacity' : 0.7, 'size' : 25}},
showlegend=False,
hoverinfo='text',
hovertext=intersections_sub['Collisions'],
customdata = intersections_sub['int_id']
)]
## return figure
return {
'data' : locations,
'layout' : go.Layout(
uirevision = 'foo',
clickmode= 'event+select',
hovermode= 'closest',
hoverdistance=2,
title= dict(text="Collision Map", font=dict(size=24, color='black')),
mapbox=dict(
accesstoken = mapbox_access_token,
bearing=0,
style = 'light',
center= dict(
lat=34.05223,
lon = -118.24368
),
pitch=40,
zoom=11.5
),
)
}
print(intersection_sub[‘Color Map’]) outpput:
[2762 rows x 68 columns]
2459 #193ca3
2460 #caee74
2461 #f2df91
2462 #f2df91
2463 #3be56a
...
5883 #f2df91
5953 #f2df91
5971 #f2df91
6014 #f2df91
6033 #f2df91
Name: Color Map, Length: 2762, dtype: object
And I get no error.
When I change my csv input and try again the print outpute is"
[2762 rows x 69 columns]
84 #193ca3
85 #caee74
86 #f2df91
87 #f2df91
88 #3be56a
...
3327 #f2df91
3395 #f2df91
3413 #f2df91
3456 #f2df91
3475 #f2df91
Name: Color Map, Length: 2762, dtype: object
And I get a Callback error updating map.figure:
ValueError:
Invalid element(s) received for the 'color' property of scattermapbox.marker
Invalid elements include: [None, None, None, None, None, None, None, None, None, None]
It seems like the Color Map series in both cases looks the same, but in the second case, something happens and the mapbox scatterplot is receiving Nones instead of the Color Map series?
Thank you for any pointers.