How pass a parameter to DASH from FLASK

I am trying to run a dash app inside a flask application as follows and i am trying to pass a FLASK input parameter (date passed as POST) to DASH, can you please let me know how to pass the DATE parameter from FLASK to DASH.

from @server.route("/home", methods=[“GET”,“POST”])

to file = ‘test_file_{}.dat’.format(DATE)

import flask
from flask import Flask, flash, render_template
import dash
import dash_html_components as html
import dash_core_components as dcc
from werkzeug.wsgi import DispatcherMiddleware
from werkzeug.serving import run_simple
import pandas as pd


server = flask.Flask(__name__)

@server.route("/")
def welcome():
   return render_template("home.html")

@server.route("/home", methods=["GET","POST"])
def home():
     if request.method=="POST":
          DATE = request.form["date"]
          try:
               return render_template("success.html")
          except ClientError as e:
               return render_template("failure.html")
     else:
          return render_template("home.html")

dash_app = dash.Dash(
    __name__,
    server=server,
    routes_pathname_prefix='/dashboard/'
)

file = 'test_file_{}.dat'.format(DATE)

df = pd.read_csv(file, header = 0)

colors = {
    'background': '#111111',
    'text': '#7FDBFF'
}
dash_app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
    html.H1(
        children='Hello Dash',
        style={
            'textAlign': 'center',
            'color': colors['text']
        }
    ),
    html.Div(children='Dash: A web application framework for Python.', style={
        'textAlign': 'center',
        'color': colors['text']
    }),
    dcc.Graph(
        id='Graph1',
        figure={
            'data': [
                {'x':df['col1'], 'y':df['col2'], 'type': 'bar', 'name': 'SF'},
                {'x':df['col1'], 'y':df['col3'], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'plot_bgcolor': colors['background'],
                'paper_bgcolor': colors['background'],
                'font': {
                    'color': colors['text']
                }
            }
        }
    )
])

@server.route('/dashboard/')
def render_dashboard():
    return flask.redirect('/dash1')

app = DispatcherMiddleware(server, {
    '/dash1': dash_app.server
})

if __name__== "__main__":
     run_simple('0.0.0.0', 8090, app, use_reloader=True, use_debugger=True)

Hey ! I’m sure this is not the best way to do it, but, you can register what you want into a session, and then access that session from dash.

@app.route('/' , methods=['GET', 'POST'])
def landing_page():
    dashboard_id = request.args.get('dashboard_id')
    
    session['dashboard_id'] = dashboard_id
    
    return redirect("/dash/")

that session is then available inside callbacks.


    @app.callback(
	[Output('store_client_id', 'data')],
	[Input('div3', 'children')])
    def update_user(children):
        try:
            s = session.get('dashboard_id', None)
            return s
        except:
            return -10

in this case i’m sending the value back to a div, but you can just access it directly from any callback you choose.

Have you solved this problem yet? I’m stuck like you
can you give me the solution please?