Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs #175

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/pages/misc_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@

with st.echo():
# call to render Folium map in Streamlit
st_folium(m, width=2000, height=500, returned_objects=[])
st_folium(m, width=2000, height=500, returned_objects=[], debug=True)
randyzwitch marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 6 additions & 6 deletions examples/pages/responsive.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@

left, right = st.columns([2, 1])
with left:
st_folium(m, use_container_width=True, key="1")
st_folium(m, use_container_width=True, key="1", debug=True)
with right:
st_folium(m, use_container_width=True, key="2")
st_folium(m, use_container_width=True, key="2", debug=True)

st_folium(m, use_container_width=True, key="3")
st_folium(m, use_container_width=True, key="3", debug=True)


col1, col2, col3 = st.columns([1, 2, 3])

with col1:
st_folium(m, use_container_width=True, key="4")
st_folium(m, use_container_width=True, key="4", debug=True)
with col2:
st_folium(m, use_container_width=True, key="5")
st_folium(m, use_container_width=True, key="5", debug=True)
with col3:
st_folium(m, use_container_width=True, key="6")
st_folium(m, use_container_width=True, key="6", debug=True)
20 changes: 18 additions & 2 deletions streamlit_folium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ def st_folium(

folium_map: folium.Map = fig # type: ignore

folium_map.render()
randyzwitch marked this conversation as resolved.
Show resolved Hide resolved

# handle the case where you pass in a figure rather than a map
# this assumes that a map is the first child
if not (isinstance(fig, folium.Map) or isinstance(fig, folium.plugins.DualMap)):
Expand Down Expand Up @@ -345,8 +347,10 @@ def bounds_to_dict(bounds_list: list[list[float]]) -> dict[str, dict[str, float]

if debug:
with st.expander("Show generated code"):
st.info("HTML:")
st.code(html)
if html:
st.info("HTML:")
st.code(html)

st.info("Main Map Leaflet js:")
st.code(leaflet)

Expand Down Expand Up @@ -387,10 +391,22 @@ def _generate_leaflet_string(
mappings = {}

mappings[m._id] = base_id
try:
element_id = m.element_name.replace("map_", "").replace("tile_layer_", "")
parent_id = m.element_parent_name.replace("map_", "").replace("tile_layer_", "")
if element_id not in mappings:
mappings[element_id] = m._parent._id
if parent_id not in mappings:
mappings[parent_id] = m._parent._parent._id
except AttributeError:
pass

m._id = base_id

if isinstance(m, folium.plugins.DualMap):
m.render()
m.m1.render()
m.m2.render()
if not nested:
return _generate_leaflet_string(
m.m1, nested=False, mappings=mappings, base_id=base_id
Expand Down
23 changes: 13 additions & 10 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,24 +221,23 @@

def test_responsiveness(page: Page):
page.get_by_role("link", name="responsive").click()
page.get_by_role("link", name="responsive").click()

page.set_viewport_size({"width": 500, "height": 3000})

initial_bbox = (
page.frame_locator("div:nth-child(2) > iframe")
.locator("#map_div")
.bounding_box()
)
try:
initial_bbox = (
page.frame_locator("iframe").nth(2).locator("#map_div").bounding_box()
)
except Exception as e:
page.screenshot(path="screenshot-responsive.png", full_page=True)
raise e

page.set_viewport_size({"width": 1000, "height": 3000})

sleep(1)

new_bbox = (
page.frame_locator("div:nth-child(2) > iframe")
.locator("#map_div")
.bounding_box()
)
new_bbox = page.query_selector_all("iframe")[2].bounding_box()

print(initial_bbox)
print(new_bbox)
Expand All @@ -249,6 +248,10 @@

assert new_bbox["width"] > initial_bbox["width"] + 300

# Check that the iframe is reasonably tall, which makes sure it hasn't failed to
# render at all
assert new_bbox["height"] > 100

page.set_viewport_size({"width": 2000, "height": 2000})


Expand All @@ -272,7 +275,7 @@

def test_dynamic_feature_group_update(page: Page):
page.get_by_role("link", name="dynamic updates").click()
page.get_by_text("Show generated code").click()

Check failure on line 278 in tests/test_frontend.py

View workflow job for this annotation

GitHub Actions / build (3.9)

test_dynamic_feature_group_update[chromium] playwright._impl._errors.TimeoutError: Timeout 30000ms exceeded.

# Test showing only Parcel layer
page.get_by_test_id("stRadio").get_by_text("Parcels").click()
Expand Down
Loading