Skip to content

Commit

Permalink
Fix popups and default return (#48)
Browse files Browse the repository at this point in the history
* Correctly render popups, and return dictionary by default, instead of null

* Bump version

* Add jinja2 and branca
  • Loading branch information
blackary authored Apr 21, 2022
1 parent f3a58e7 commit e6b20b2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
streamlit>=1.2.0
folium>=0.11
jinja2
branca
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="streamlit_folium",
version="0.6.5",
version="0.6.6",
author="Randy Zwitch",
author_email="[email protected]",
description="Render Folium objects in Streamlit",
Expand All @@ -13,5 +13,5 @@
include_package_data=True,
classifiers=[],
python_requires=">=3.7",
install_requires=["streamlit>=1.2", "folium>=0.11"],
install_requires=["streamlit>=1.2", "folium>=0.11", "jinja2", "branca"],
)
16 changes: 15 additions & 1 deletion streamlit_folium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def st_folium(
fig = list(fig._children.values())[0]

leaflet = generate_leaflet_string(fig)

# Replace the folium generated map_{random characters} variables
# with map_div and map_div2 (these end up being both the assumed)
# div id where the maps are inserted into the DOM, and the names of
Expand All @@ -132,6 +133,14 @@ def st_folium(
key=generate_js_hash(leaflet, key),
height=height,
width=width,
default={
"last_clicked": None,
"last_object_clicked": None,
"all_drawings": None,
"last_active_drawing": None,
"bounds": fig.get_bounds(),
"zoom": fig.options.get('zoom'),
}
)

return component_value
Expand All @@ -155,7 +164,12 @@ def generate_leaflet_string(m: folium.MacroElement, nested: bool = True) -> str:
leaflet += m._template.module.script(m)
return leaflet

leaflet = m._template.module.script(m)
try:
leaflet = m._template.module.script(m)
except UndefinedError:
# Correctly render Popup elements, and perhaps others. Not sure why
# this is necessary. Some deep magic related to jinja2 templating, perhaps.
leaflet = m._template.render(this=m, kwargs={})

if not nested:
return leaflet
Expand Down

0 comments on commit e6b20b2

Please sign in to comment.