I want to do HTML formatting into a folium map popup. When I try to render html by using def format_popup_content(row)
function then the map does not display. How do I format popup?
This is what I have tried so far
def format_popup_content(row):
# Format the popup content using HTML
popup_content = f"""
<div style="font-family: Arial, sans-serif;">
<h2 style="margin-bottom: 5px; text-align: center;">District: {row['district']}</h2>
<table style="width: 100%;">
<tr>
<td style="font-weight: bold;">Diagnose:</td>
<td>{row['provisionaldiagnose']}</td>
</tr>
<tr>
<td style="font-weight: bold;">Age:</td>
<td>{row['age']}</td>
</tr>
<tr>
<td style="font-weight: bold;">Gender:</td>
<td>{row['pgender']}</td>
</tr>
<!-- Add more information here if needed -->
</table>
</div>
"""
return popup_content
This is the code of popup functionality
popup_text = folium.Html(format_popup_content(row), script=True)
iframe = branca.element.IFrame(html=popup_text, width=320, height=500)
popup = folium.Popup(iframe, parse_html=True)
# Update the color parameter to use the corresponding color from the color dictionary
folium.CircleMarker([lat, lon], radius=7, color=color, opacity=1.0, fill_color=color, popup=popup).add_to(district_layers[district])