Hello everyone,
I am trying to make an application that is mainly built on flask but has a small use of Dash. In my current use case, the application will take inputs from flask and when submitted, it will redirect to dash. In Dash I have used dash-leaflet to get the co-ordinates of a point based on mouse click, but after the mouse click I want it to be redirected back to the flask app. How do you do this? Below is a sample of my code.
import dash
import dash_leaflet as dl
import dash_leaflet.express as dlx
import dash_html_components as html
from dash.dependencies import Input, Output
import dash_core_components as dcc
import pandas as pd
import mapping as mp
from flask import Flask, render_template, request, redirect, session, url_for
server = Flask(__name__)
server.secret_key = 'secret_key_X'
@server.route('/')
def main():
return render_template('tourist.html')
@server.route('/tourist/latlong', methods=['GET', 'POST'])
def latlong():
if request.method == 'POST':
form_data = request.form.to_dict(flat=False)
session['form_data'] = form_data
return redirect('/map_click/')
app = dash.Dash(prevent_initial_callbacks=True, server=server)
app.layout = html.Div(style={'textAlign': 'center', "color":"#31354b", 'font-family': 'Arial' },children=[
dl.Map([dl.TileLayer(), dl.LayerGroup(id='layer')],
id='map', style={'width':'100%','height':'50vh','margin':'auto','display':'block'}),
html.H3('Sample Text', className='lead')])
@app.callback(Output('layer', 'children'), [Input('map', 'click_lat_lng')])
def map_click(click_lat_lng):
session['lat_long'] = click_lat_lng
print(click_lat_lng)
if click_lat_lng:
return redirect(url_for('tourist'))
if __name__ == '__main__':
app.run_server(debug=True)
Any help is appreciated,
Thankyou!