|
10 | 10 | import branca |
11 | 11 | import folium |
12 | 12 | import folium.plugins |
| 13 | +import streamlit as st |
13 | 14 | import streamlit.components.v1 as components |
14 | 15 | from jinja2 import UndefinedError |
15 | 16 |
|
@@ -153,6 +154,7 @@ def _get_feature_group_string( |
153 | 154 | ) -> str: |
154 | 155 | feature_group_to_add._id = "feature_group" |
155 | 156 | feature_group_to_add.add_to(map) |
| 157 | + feature_group_to_add.render() |
156 | 158 | feature_group_string = generate_leaflet_string( |
157 | 159 | feature_group_to_add, base_id="feature_group" |
158 | 160 | ) |
@@ -180,6 +182,7 @@ def st_folium( |
180 | 182 | feature_group_to_add: folium.FeatureGroup | None = None, |
181 | 183 | return_on_hover: bool = False, |
182 | 184 | use_container_width: bool = False, |
| 185 | + debug: bool = False, |
183 | 186 | ): |
184 | 187 | """Display a Folium object in Streamlit, returning data as user interacts |
185 | 188 | with app. |
@@ -218,6 +221,9 @@ def st_folium( |
218 | 221 | use_container_width: bool |
219 | 222 | If True, set the width of the map to the width of the current container. |
220 | 223 | This overrides the `width` parameter. |
| 224 | + debug: bool |
| 225 | + If True, print out the html and javascript code used to render the map with |
| 226 | + st.code |
221 | 227 | Returns |
222 | 228 | ------- |
223 | 229 | dict |
@@ -298,6 +304,17 @@ def bounds_to_dict(bounds_list: List[List[float]]) -> Dict[str, Dict[str, float] |
298 | 304 | map=folium_map, |
299 | 305 | ) |
300 | 306 |
|
| 307 | + if debug: |
| 308 | + with st.expander("Show generated code"): |
| 309 | + st.info("HTML:") |
| 310 | + st.code(html) |
| 311 | + st.info("Main Map Leaflet js:") |
| 312 | + st.code(leaflet) |
| 313 | + |
| 314 | + if feature_group_string is not None: |
| 315 | + st.info("Feature group js:") |
| 316 | + st.code(feature_group_string) |
| 317 | + |
301 | 318 | component_value = _component_func( |
302 | 319 | script=leaflet, |
303 | 320 | html=html, |
|
0 commit comments