<jupyter_start><jupyter_text>Demonstrates the use of [`Folium`](https://python-visualization.github.io/folium/) in Panel.<jupyter_code>import folium as fm
import pandas as pd
import param
import panel as pn
import random
pn.extension()<jupyter_output><empty_output><jupyter_text>You can use `Folium` directly in a Jupyter Notebook<jupyter_code>def get_map(lat=20.5936832, long=78.962883, zoom_start=5):
    return fm.Map(location=[lat,long], zoom_start=zoom_start)

map = get_map()

pn.panel(map)<jupyter_output><empty_output><jupyter_text>Interactive Panel app using FoliumLet build an interactive Panel application using Folium.Lets **define some data**.<jupyter_code>def get_df_aqi(lat_bounds=(10,30), long_bounds=(70,90), points_count=40):
    aqi = {
        "Latitude": [random.uniform(*lat_bounds) for _ in range(0,points_count)],
        "Longitude": [random.uniform(*long_bounds) for _ in range(0,points_count)],
        "AQI": [random.uniform(0,500) for _ in range(0,points_count)],
    }
    return pd.DataFrame(aqi)

df_aqi = get_df_aqi()
df_aqi.sample(5)<jupyter_output><empty_output><jupyter_text>Lets define some functionality to **add the data to the map** as circles<jupyter_code>def add_aqi_circles(map, df_aqi):
    green_p1  = fm.map.FeatureGroup()
    yellow_p1 = fm.map.FeatureGroup()
    orange_p1 = fm.map.FeatureGroup()
    red_p1    = fm.map.FeatureGroup()
    purple_p1 = fm.map.FeatureGroup()
    maroon_p1 = fm.map.FeatureGroup()

    for _, row in df_aqi.iterrows():
        if row.AQI<50:
            feature_group = green_p1
            fill_color = "green"
        elif row.AQI < 100:
            feature_group = yellow_p1
            fill_color = "yellow"
        elif row.AQI < 150:
            feature_group = orange_p1
            fill_color = "orange"
        elif row.AQI < 200:
            feature_group = red_p1
            fill_color = "red"
        elif row.AQI < 300:
            feature_group = purple_p1
            fill_color='purple'
        else:
            feature_group = maroon_p1
            fill_color = "maroon"

        feature_group.add_child(
            fm.CircleMarker(
                [row.Latitude, row.Longitude],
                radius=10, 
                fill=True,
                fill_color=fill_color,
                fill_opacity=0.7
            )
        )

    map.add_child(green_p1)
    map.add_child(yellow_p1)
    map.add_child(orange_p1)
    map.add_child(red_p1)
    map.add_child(purple_p1)

add_aqi_circles(map, df_aqi)
pn.panel(map)<jupyter_output><empty_output><jupyter_text>Lets put it all together into an **interactive app** where the user can select the number of data points to generate and display.<jupyter_code>class PanelFoliumMap(param.Parameterized):
    points_count = param.Integer(20, bounds=(10,100))
        
    def __init__(self, **params):
        super().__init__(**params)
        self.map = get_map()
        self.html_pane = pn.pane.HTML(sizing_mode="stretch_width", min_height=600)    
        self.view = pn.Column(
            self.param.points_count,
            self.html_pane,
            sizing_mode="stretch_width", min_height=600,
        )
        self._update_map()

    @param.depends("points_count", watch=True)
    def _update_map(self):
        self.map = get_map()
        df_aqi = get_df_aqi(points_count=self.points_count)
        add_aqi_circles(self.map, df_aqi)
        self.html_pane.object = self.map

        
app = PanelFoliumMap()
app.view.embed()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1088939566704675, 'fraction_numerical': 0.02394526795895097, 'mean_word_length': 2.898888888888889, 'pattern_counts': {'":': 3, '<': 26, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '184178', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1208, 'n_words': 219, 'path': 'examples/gallery/external/Folium.ipynb', 'repo_name': 'slamer59/panel', 'size': '3508'}