Summary
Hello streamlit community, I would like some guidance on how to properly use the st.map widget. I am trying to show coordinates stored in a simple dictionary. The widget does not correctly show the location of the coordinates.
Code snippet:
some_location = {"lon":-6.175226341354826,"lat":106.82701971424365}
st.map(some_location)
Expected behavior:
As per the parameter description of the st.map function, the function is compatible with the ‘dict’ structure.
Error message:
2022-11-07 09:56:44.293 Uncaught app exception
Traceback (most recent call last):
File "C:\Users\MKurniawan\.conda\envs\MSDGI\lib\site-packages\streamlit\scriptrunner\script_runner.py", line 557, in _run_script
exec(code, module.__dict__)
File "Home.py", line 211, in <module>
mid_row()
File "Home.py", line 153, in mid_row
st.map(map_df)
File "C:\Users\MKurniawan\.conda\envs\MSDGI\lib\site-packages\streamlit\elements\map.py", line 74, in map
map_proto.json = to_deckgl_json(data, zoom)
File "C:\Users\MKurniawan\.conda\envs\MSDGI\lib\site-packages\streamlit\elements\map.py", line 144, in to_deckgl_json
if data is None or data.empty:
AttributeError: 'dict' object has no attribute 'empty'
My work-around
In order to mitigate this, I converted the dictionary to the pandas data frame. This works, but does not display the points at the correct coordinates.
# Default locations
loc_data = {
"longitude": [
52.29274500131053,
52.48445527569644,
50.42902450689658,
24.977514892279544,
50.974819434969845,
3.0933771882453205,
],
"latitude": [
6.90964804526128,
7.332599016521705,
30.51765681207883,
55.08787764229468,
-113.99429073143872,
101.56100788451147,
],
}
map_df = pd.DataFrame.from_dict(loc_data)
# Create a map
st.map(map_df)
I’m simply trying to show some plots correctly on the map.
Any guidance is appreciated.
Thanks in advance!
Arief.