[GIS] How to add data slider bar control to Folium maps

choroplethfoliumjavascriptleaflet

I am making a choropleth map in Folium which displays data for certain age brackets. I would like to add a double ended slider letting users select the bottom and top of the age range to view. The data is from the census which has 14 different age brackets. Thus the slider should have discretized stopping points corresponding to the age ranges specified by the Census data. Something like this: https://digital-geography.com/filter-leaflet-maps-slider/

The only way I know how to do this in Folium would be to make each possible pair of ages its own layer and then switch between them in the layer menu. However this would increase the amount of data I would have by a factor of 98, and the map is already 270 KB with a single layer. So it would be an almost 20 MB webpage if I do it this way! Plus I would not have a slider.

Is there some other way of doing my desired functionality with an actual slider instead of the layer controls and without having to store such a large HTML page?

Best Answer

Plotting Layers and Titles in Folium

I add an answer in case someone needed it in the future.

import folium
m2=folium.Map(location=loc)
folium.TileLayer('Stamen Terrain').add_to(m2)
folium.TileLayer('Stamen Toner').add_to(m2)
folium.TileLayer('Stamen Water Color').add_to(m2)
folium.TileLayer('cartodbpositron').add_to(m2)
folium.TileLayer('cartodbdark_matter').add_to(m2)
folium.LayerControl().add_to(m2)

m2