Q: folium map not refreshing data on map and displaying previous data visualizations I have used folium library to create a map Stamen Toner and it worked great.but when I try to refresh the data to visualize other result it keep showing the previous result.


from flask import Flask, request, render_template,make_response,Response
import io
import csv
import pandas as pd
import numpy as np
from flask_googlemaps import GoogleMaps
from flask_googlemaps import Map,icons
import folium


app = Flask(__name__, static_url_path = "/tmp", static_folder = "tmp")



@app.route('/')
def my_form():
    return render_template('myform.html')



@app.route('/', methods=['POST'])
def my_form_post():
    text = request.form['search']
    #processed_text = text.upper()
    df = pd.read_csv('func_latest.csv',engine='python')
    #df1 = df[(df.topic == text)]
    df['topic'] = df['topic'].str.lower()
    words=text.split(" ")
    print(words)

    df1=df[df.topic.str.contains(text)==True]
    print(df1)


    map = folium.Map(location=[0, 0], zoom_start=2, tiles='Stamen Toner')
    def color(contry):
        col = ''
        df = df1
        print(df)
        score = 0
        for row in df.itertuples():
            if row.country == contry:
                score = score + row.sentiment
                if score == 0:
                    col = 'darkblue'
                if score > 0:
                    col = 'green'
                if score < 0:
                    col = 'darkred'
        return col

    map.add_child(folium.GeoJson(data=open('world_geojson_from_ogr.json', encoding="utf-8-sig").read(),
                                 name="Population",
                                 style_function=lambda x: {
                                     'fillColor': color(x['properties']['NAME']) if x['properties'][
                                                                                        'NAME'] == 'Pakistan'
                                     else color(x['properties']['NAME']) if x['properties']['NAME'] == 'India'
                                     else color(x['properties']['NAME']) if x['properties']['NAME'] == 'China'
                                     else color(x['properties']['NAME']) if x['properties']['NAME'] == 'United States'
                                     else color(x['properties']['NAME']) if x['properties']['NAME'] == 'United Kingdom'
                                     else 'white'}))
    map.add_child(folium.LayerControl())

    map.save(outfile='C:/Users/LENOVO_PC/PycharmProjects/untitled1/templates/map.html')
    return render_template('map.html')

import os
if __name__ == "__main__":
    if os.path.exists("map.html"):
        os.remove("map.html")
    app.run()


This is showing the updated result in console but it is not refreshing the Map and showing the updated visualizations of sentiments on Map.
Folium map visualization at first glance
Thank you in advance.

A: I had the same issue.
Flask does not by default refresh templates . You can set
app.config['TEMPLATES_AUTO_RELOAD'] = True

where you define the flask app
app = Flask(__name__)

details can be found here http://flask.pocoo.org/docs/1.0/config/
