I’m new to Dash and currently working on a project involving a large dataset from USDA. I’ve successfully created a choropleth map at the county level, but I’m facing challenges with a specific feature. I need to implement functionality where clicking on a county triggers a radius (user-defined) that highlights all counties within that radius. The aim is to either display the values of these counties directly on the map or present them in a table format. I’m unsure about how to approach the radius feature and would appreciate any guidance or suggestions.
like I said new here but eager to learn and hope I can get some clarity.
Thanks!
Hello @Conorl86,
Welcome to the community!
It might be helpful if you create an example of the code to get started with finding some help.
I’d suggest looking into using dl.Map(dl.FeatureGroup([dl.LocateControl(locateOptions={‘enableHighAccuracy’: True, ‘drawMarker’:True, ‘flyTo’:True, ‘showCompass’:True}),dl.EditControl(id=“edit_control”) ])) then just return the results of the section drawn on map into a callback-based off the “edit_control” Input and using it to run the functions for filtering sites before returning a table or counter component.
Also check out this video, you might find it helpful for some aspect of your project: https://www.youtube.com/watch?v=OVggxyO81CQ&t=1132s
fig = px.choropleth(filtered_data, geojson=counties, locations='fips', color='Value',
color_continuous_scale="Viridis",
scope="usa",
labels={'Value':'productiontest'})
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0}, clickmode='event+select')
elif trigger_id == 'choropleth-map':
fig = go.Figure(current_figure)
if clickData:
clicked_fips = clickData['points'][0]['location']
centroid = centroids.get(clicked_fips)
if centroid:
lat, lon = centroid.y, centroid.x
circle_radius_degree = 50 / 69
fig.add_shape(
type='circle',
xref='x',
yref='y',
fillcolor='blue',
opacity=0.3,
x0=lon - circle_radius_degree,
y0=lat - circle_radius_degree,
x1=lon + circle_radius_degree,
y1=lat + circle_radius_degree,
line_color='blue',
)
return fig
return fig
this is how I was trying to do it
Ok I’ll check this out yeah I was thinking I might have to change the library I use for the map