So what I want is to set the edge color of a specific polygon that meets one condition. May be df.index=1(or any index) or df[df[ācolumn_nameā]=='any_cell_value"] but Iām not being able to do it.
I tried out this:
fig.for_each_trace(
lambda trace: trace.update(marker_line_color="green") if selector==dict(column_name='any_cell_value') else (),
)
But it added green borders to all polygons. And I also tried out add_choroplethmapbox but Iām getting several errors.
Thanks for your answer but I canāt totally understand the first part of the solution (the JavaScript snippet part) and how itās integrated with the Dash app. Iām new at dashboarding with python and Iām kinda lost!
@Emil btw, what I want is to set the color of the edge, not the color of the entire polygon
and i also wrote some docs on this kind of use case,
You can change any style property of the polygon, to change the edge color i guess you could keep the fillColor constant and change the color dynamically.
This is probably too late, but I couldnāt find a good answer anywhere so figured Iād contribute.
My solution is pretty hacky, but I think achieves what you are trying to do.
I added additional choropleth traces with opacity 0 but with a thick marker line width/color. Iām sure there is a more efficient way of doing this but the code below pulls out the specific geojson features that you want (by name) and creates a new trace for just that county (or country/state/province) with opacity 0 so it doesnāt block out your initial data, but still highlights the selected areas.
for i in range(len(df)):
for c in counties['features']:
if c['properties']['NAME'] == df['county'][i]:
break
if c['properties']['NAME'] in ['Los Angeles', 'Miami-Dade', 'Suffolk']:
fig.add_trace(go.Choropleth({"marker_line_color":"red",'featureidkey': 'properties.NAME',
'geo': 'geo',"marker_line_width":2, 'geojson':c, 'z': [df['count'][i]], 'locations': [df['county'][i]], 'colorscale': [[0,'rgba(0,0,0,0)'],[1,'rgba(0,0,0,0)']], 'colorbar':None, 'showlegend': False}))