Folium has been the subject of numerous threads and feature requests, so I decided to kickoff the beginning of Folium support within Streamlit!
Installation is as straightforward as:
pip install streamlit-folium
Example
import streamlit as st
from streamlit_folium import folium_static
import folium
"# streamlit-folium"
with st.echo():
import streamlit as st
from streamlit_folium import folium_static
import folium
# center on Liberty Bell
m = folium.Map(location=[39.949610, -75.150282], zoom_start=16)
# add marker for Liberty Bell
tooltip = "Liberty Bell"
folium.Marker(
[39.949610, -75.150282], popup="Liberty Bell", tooltip=tooltip
).add_to(m)
# call to render Folium map in Streamlit
folium_static(m)
This Component uses components.html to take the HTML generated from a folium.Map or folium.Figure object render() method, and display it as-is within Streamlit.
Limitations and Future Development
As Iāve mentioned in other Folium threads, I hadnāt even heard of Folium until people started requesting it! So Iām barely on the scale of a new Folium user. Testing was done by going through the Folium quickstart and copy-pasting results to see if they work. They do appear to work, providing a similar experience to Jupyter Notebook rendering.
That said, not being an intense Folium user, I welcome users to try this component and file issues when you come across them. Currently, the Component is static, which means that it just renders the Python object as it exists, there are no callbacks from interacting with the Folium object via JavaScript.
I welcome Folium enthusiasts to contribute to this package to make it what YOU want to see.
I believe thatās just a plain Folium questionā¦if itās possible with Folium, it should be possible in the streamlit-folium plugin, as all Iām doing at the moment is using the HTML from one of the Folium display methods
Fantastic, what I want to create is an app where location (lat/lon) tagged images can be browsed on a google map interface, and when you click on a pin you get a view of the image. Will keep you posted of any progress.
Hi Randy - thanks for your reply.
width and height are restricted to 500 I suppose. What I want is to extend the map to width of the page same as we could do with other widgets. It seems that we are restricted to small view for folium here. Could you point me to any example if it is achievable
Thanks so much for this component. I was struggeling with deckgl quite a bit and find streamlit-folium much more straigt-forward to use. Is there a way to set the size of the markers?
I have been doing some work of creating a folium choropleth map in python and trying to embed that within streamlit. Whilst I have been successful in getting the map displayed within streamlit via:
folium_static(my_map, width=1200, height=700),
for some reasons the legend of the map is not getting displayed in the map. But if I save the map as a stand alone html file and then open it in a separate webpage ( just the map that I saved as html), the legend is displayed there. The python command I used to save it as an html file was :
my_map.save(āsample_map.htmlā).
Can you please help me in getting this matter resolved and show my full map(including itās legend) to be displayed within streamlit.
NB: I also attempted to do as follows, but no joy in doing that either:
st.markdown(my_map.repr_html_(), unsafe_allow_html=True), as I was getting a " āMapā object has no attribute ārepr_html_ā " error message.
Can you post the code you are using to generate the map? In general, if you are using folium_static, itās reading the HTML from the Folium object, so it feels like it should work as-is.
Do you have any advice to keep the map (choropleth) from consistently re-rendering any time the map is panned, zoomed, or otherwise changed by the user? Iāve tried @st.cache in several ways but cannot get it to work effectively without throwing error messages.
As Iāve been using Folium to plot some maps and trying to display them in streamlit I used Folium_static(), but Iāve got a problem as the maps cannot be modified after calling Folium_static().
Is there any other approach or solution for this problem?!
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking āAccept allā, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.