The goal is to be able to select elements on a map, and then access the selected elements in streamlit. And also to update elements on a map, based on events that happened in streamlit.
For example:
- Select points on a map, with points coloured by a category variable.
- View the selected points as a table.
- Change catagory value of all the selected points.
- Update the color of the points on the map.
The latest example can be found in at examples/plotly_mapbox_aggrid_multi_select_change_update.py
.
A video of an older example can can be viewed here: https://youtu.be/2rIpb0LyNgc
Refer to the "Examples" section for a list of all examples, chronologically built and extended.
The closest existing component found for the above is:
- https://github.com/null-jones/streamlit-plotly-events
- https://github.com/reyemb/streamlit-plotly-mapbox-events
And a demo that shows plotly being used in this way:
- https://github.com/andfanilo/social-media-tutorials/blob/master/20220914-crossfiltering/streamlit_app.py with a video here: https://youtu.be/htXgwEXwmNs
Just basic illustration of interaction on the map and what is returned via the streamlit-plotly-mapbox-events component:
examples/plotly_mapbox_events_example.py
: original example with a bit of modication from https://github.com/reyemb/streamlit-plotly-mapbox-events (done for issue #4)examples/plotly_mapbox_events_carshare_example.py
: example above extended with example from https://plotly.com/python/scattermapbox/ (done for issue #4)
Dataframes are filtered and displayed based on events returned from the streamlit-plotly-mapbox-events component. It also includes filtering the data-frame based on the map viewpoint (when zooming and panning). There is still a short-comming in that the map resets to its original viewpoint when events happen.
examples/plotly_mapbox_events_carshare_dataframe_filter.py
: extension ofexamples/plotly_mapbox_events_carshare_example.py
(done for issue #6)
Same functionality as above, and with zoom level and pan level maintained:
examples/plotly_mapbox_events_carshare_consistent_map_layout.py
: extension ofexamples/plotly_mapbox_events_carshare_dataframe_filter.py
(done for issue #8)
This forms the basis for more exotic examples.
Known issues:
- Sometimes the map jitters too and from the previous selection area. See issue #9.
- When using multiple draw selects (pressing down shift key), the retained draw shapes are as per the previous viewpoint (not the current one). See issue #10
A reduced version of the above, where points are highlighted on the map when selected in a dataframe:
examples/plotly_mapbox_events_carshare_consistent_map_dataframe_highligh.py
: done for issue #12
Similar to "Potly map interaction with zoom-level retained", but here the points are already coloured based on a category variable. New red points are overlayed to show selections.
examples/plotly_mapbox_events_carshare_pre_color_non_clash_select.py
: done for issue #14
A comprehensive example, building on all the above. Points can be selected via a table or directly on the map, and can then be reassigned to a new route.
examples/plotly_mapbox_aggrid_multi_select_change_update.py
: done for issue #16
To get it fully up and running in shell:
poetry shell
source $(poetry env info --path)/bin/activate