question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Beautify Icon does not work when used in a for loop

See original GitHub issue

Hi

I am using BeautifyIcon to create a star shaped marker.

Issue I’m facing is: When I run the below code the , it runs as expected and plots a star mark at required Lat Lon

m = folium.Map([45.5, -122], zoom_start=3)

icon_star = plugins.BeautifyIcon(icon="star",text_color='#b3334f',
                                 background_color='transparent',border_color='transparent',
                                 inner_icon_style='font-size:20px')


folium.Marker(
    location=[46, -122],
    popup='Portland, OR',
    icon=icon_star
).add_to(m)

m

image

But Whein I try to run for a Dataframe on loop of more than 4000 data, the Icon is not plotted, Code below.

icon_star = plugins.BeautifyIcon(icon="star",text_color='#b3334f',
                                 background_color='transparent',border_color='transparent',
                                 inner_icon_style='font-size:20px')
m = folium.Map([28.1, 77.1],zoom_start=8)
for i,rows in df[['Lat','Long']].iterrows():
    folium.Marker(location=[rows['Lat'],rows['Long']],icon=icon_star).add_to(m)

image

This is how my data looks.

image

I don’t know why is this happening, It should give me star plotted for all the lat lon, but I get one single marker which is not a star either.

Environment (please complete the following information):

  • Browser => Chrome
  • Jupyter Notebook or html files => Jupyter notebook
  • Python versions => ys.version_info(major=3, minor=6, micro=10, releaselevel=‘final’, serial=0)
  • folium version => 0.11.0
  • branca version => 0.4.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
scigliocommented, Dec 29, 2020

Hello, I had the same problem. I went around it using:

icon=plugins.BeautifyIcon(icon=“star”,text_color=‘#b3334f’, background_color=‘transparent’,border_color=‘transparent’, inner_icon_style=‘font-size:20px’)

directly in the loop:

for i,rows in df[[‘Lat’,‘Long’]].iterrows(): folium.Marker(location=[rows[‘Lat’],rows[‘Long’]],icon=plugins.BeautifyIcon(icon=“star”,text_color=‘#b3334f’, background_color=‘transparent’,border_color=‘transparent’, inner_icon_style=‘font-size:20px’) ).add_to(m)

0reactions
Conengmocommented, Nov 22, 2022

Unfortunately as folium is now you cannot re-use an icon. Instead you have to create each icon object in the loop as well:


m = folium.Map([28.1, 77.1],zoom_start=8)
for i,rows in df[['Lat','Long']].iterrows():
    icon_star = plugins.BeautifyIcon(icon="star",text_color='#b3334f',
                                 background_color='transparent',border_color='transparent',
                                 inner_icon_style='font-size:20px')
    folium.Marker(location=[rows['Lat'],rows['Long']],icon=icon_star).add_to(m)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Beautify Icon does not work when used in a for loop
I am using BeautifyIcon to create a star shaped marker. Issue I'm facing is: When I run the below code the , it...
Read more >
Beautiful Soup not working in for loop more than once
It is a password-protected website I'm using selenium-wire to get a login and then copy a request body. I can provide the HTML...
Read more >
for-Loop in R (10 Examples) | Writing, Running & Using Loops ...
In this Example, I'll illustrate how to use for-loops to loop over a vector. In the following R code, we are specifying within...
Read more >
plugins — Folium 0.12.1 documentation - GitHub Pages
Create a BeautifyIcon that can be added to a Marker. Parameters. icon (string, default None) – the Font-Awesome icon name to use to...
Read more >
How to Add Drag and Drop in React with React Beautiful DnD
Note: This function can pass in two arguments including a snapshot argument, but we won't be using it in this example. The provided...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found