Repository: streamlit/streamlit

Issue:
st.map() does not refresh with the new data
### Checklist

- [X] I have searched the [existing issues](https://github.com/streamlit/streamlit/issues) for similar issues.
- [X] I added a very descriptive title to this issue.
- [X] I have provided sufficient information below to help reproduce this issue.

### Summary

Using the example code from tutorial to show the uber data on NY map. After inserting the slider code I was expecting to see the map refresh based on the value from the slider. But it only refreshes if I resize and reset the map.

I am using the cloud version.



### Reproducible Code Example

```Python
import pandas as pd
import numpy as np
import streamlit as st

st.title('Uber pickups in NYC')

DATE_COLUMN = 'date/time'
DATA_URL = ('https://s3-us-west-2.amazonaws.com/'
         'streamlit-demo-data/uber-raw-data-sep14.csv.gz')

@st.cache_data
def load_data(nrows):
    data = pd.read_csv(DATA_URL, nrows=nrows)
    lowercase = lambda x: str(x).lower()
    data.rename(lowercase, axis='columns', inplace=True)     
    data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN])
    return data

data_load_state = st.text('loading data ...')
data = load_data(10000)
data_load_state.text('done (cached data).')

if st.checkbox('show raw data'):
    st.subheader('Raw data')
    st.write(data)

st.subheader('Number of pickups by hour')
hist_values = np.histogram(
    data[DATE_COLUMN].dt.hour, bins=24, range=(0,24))[0]
st.bar_chart(hist_values)

hour_to_filter = st.slider('hour', 0, 23, 6)  # min: 0h, max: 23h, default: 17h
st.subheader(f'Map of all pickups at {hour_to_filter}:00')
filtered_data = data[data[DATE_COLUMN].dt.hour == hour_to_filter]
st.write(f'read nrows: {len(filtered_data)}')
st.map(filtered_data)
```


### Steps To Reproduce

1. change the hour_to_filter to 17 using the slider
2. filtered_data gets changed accordingly
3. the map does not change with the changed value of filtered_data

### Expected Behavior

st.map() should refresh if the data (in this case, filtered_data) changed.

### Current Behavior

There is no error displayed. The map is not refreshed.

[https://discuss.streamlit.io/t/st-map-does-not-refresh-the-map-automatically/51150](url)

### Is this a regression?

- [ ] Yes, this used to work in a previous version.

### Debug info

- Streamlit version:
- Python version:
- Operating System:
- Browser:


### Additional Information

Here is the link to my app: [https://rakesh-k-streamlit-example-streamlit-app-y4qpgs.streamlit.app](url)


Discussion:
**If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.**

Your feedback helps us prioritize which bugs to investigate and address first.

![Visits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fstreamlit%2Fstreamlit%2Fissues%2F7294&title=visits&edge_flat=false)


Resolving patch:
diff --git a/lib/streamlit/elements/map.py b/lib/streamlit/elements/map.py
--- a/lib/streamlit/elements/map.py
+++ b/lib/streamlit/elements/map.py
@@ -15,6 +15,7 @@
 """A wrapper for simple PyDeck scatter charts."""
 
 import copy
+import hashlib
 import json
 from typing import (
     TYPE_CHECKING,
@@ -238,12 +239,11 @@ def map(
         #       for information on how to get one and set it up in Streamlit.
         #
         map_style = None
-
         map_proto = DeckGlJsonChartProto()
-        map_proto.json = to_deckgl_json(
+        deck_gl_json = to_deckgl_json(
             data, latitude, longitude, size, color, map_style, zoom
         )
-        map_proto.use_container_width = use_container_width
+        marshall(map_proto, deck_gl_json, use_container_width)
         return self.dg._enqueue("deck_gl_json_chart", map_proto)
 
     @property
@@ -483,3 +483,17 @@ def _get_zoom_level(distance: float) -> int:
 
     # For small number of points the default zoom level will be used.
     return _DEFAULT_ZOOM_LEVEL
+
+
+def marshall(
+    pydeck_proto: DeckGlJsonChartProto,
+    pydeck_json: str,
+    use_container_width: bool,
+) -> None:
+    json_bytes = pydeck_json.encode("utf-8")
+    id = hashlib.md5(json_bytes).hexdigest()
+
+    pydeck_proto.json = pydeck_json
+    pydeck_proto.use_container_width = use_container_width
+
+    pydeck_proto.id = id


Test patch:
diff --git a/lib/tests/streamlit/elements/map_test.py b/lib/tests/streamlit/elements/map_test.py
--- a/lib/tests/streamlit/elements/map_test.py
+++ b/lib/tests/streamlit/elements/map_test.py
@@ -382,3 +382,14 @@ def test_pyspark_dataframe(self):
 
         """Check if map data has 5 rows"""
         self.assertEqual(len(c["layers"][0]["data"]), 5)
+
+    def test_id_changes_when_data_changes(self):
+        st.map()
+
+        orig_id = self.get_delta_from_queue().new_element.deck_gl_json_chart.id
+        np.random.seed(0)
+
+        df = pd.DataFrame({"lat": [1, 2, 3, 4], "lon": [10, 20, 30, 40]})
+        st.map(df)
+        new_id = self.get_delta_from_queue().new_element.deck_gl_json_chart.id
+        self.assertNotEquals(orig_id, new_id)