Folium is a powerful Python library that enables the creation of interactive maps. Many data scientists and analysts prefer using Folium for its ease of use and rich functionality. However, when working in Deepnote, you might encounter issues displaying Folium maps due to security restrictions and the unique architecture of the Deepnote platform. We will provide you solution to common problem of rendering Folium maps in Deepnote.
The problem: Trusted notebooks in Deepnote
When attempting to use Folium in Deepnote, users often encounter the following message:
Make this Notebook Trusted to load map: File -> Trust Notebook
In Jupyter notebooks, this issue can be resolved by trusting the notebook. However, Deepnote operates differently and does not utilize the same “trusted notebook” concept as Jupyter. Due to security constraints, Deepnote does not support Folium out of the box. Here is a workaround that you can use to bypass this.
The solution: A custom function to display Folium maps
Fortunately, there is a workaround to display Folium maps. This involves defining a custom function at the beginning of your notebook. The function adjusts the rendered HTML from Folium to be compatible with Deepnote.
Define the custom function
from IPython.display import display, HTML
def folium_deepnote_show(m):
data = m.get_root().render()
data_fixed_height = data.replace('width: 100%;height: 100%', 'width: 100%').replace('height: 100.0%;', 'height: 609px;', 1)
display(HTML(data_fixed_height)
Create and display a Folium map
import folium
# Create a Folium map
m = folium.Map(location=[45.5236, -122.6750], zoom_start=13)
# Display the map using the custom function
folium_deepnote_show(m)
Example notebook
For a more comprehensive example, you can check example notebook, which demonstrates how to use this custom function with various Folium features.
Conclusion
While Deepnote does not support the “trusted notebook” functionality like Jupyter, you can still use Folium to create and display interactive maps by leveraging a custom display function. This workaround ensures that your Folium maps render correctly in Deepnote, allowing you to continue visualizing your spatial data effectively.
If you encounter further issues, don't hesitate to get in touch with our support. Happy mapping in Deepnote!