Dash in IIS using Flask server?

I have added a Dash website to my development environment (Windows 2008 R2 and IIS - and no I don’t have any choice about this). My question is - does the method I am using use the Flask development server, and if so, is there a better way to deliver the content? I have read that the Flask server should not be used in deployment environments (If the answer seems obvious to you, I am just learning about Flask and Dash):

import flask
from datetime import datetime as dt
import dash
import dash_html_components as html
import dash_core_components as dcc

server = flask.Flask(__name__)

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, server=server, external_stylesheets=external_stylesheets)
app.layout = html.Div([
        html.H3(children='Pick a Date'),

        dcc.DatePickerSingle(
        id='my-date-picker-single',
        min_date_allowed=dt(2018, 1, 1),
        max_date_allowed=dt.now(),
        initial_visible_month=dt.now(),
        date=dt.now()
    ),
    html.Div(id='output-container-date-picker-single')
])


@app.callback(
    dash.dependencies.Output('output-container-date-picker-single', 'children'),
    [dash.dependencies.Input('my-date-picker-single', 'date')])
def update_output(date):
    string_prefix = 'You have selected: '
    if date is not None:
        date = dt.strptime(date, '%Y-%m-%d')
        date_string = date.strftime('%B %d, %Y')
        return string_prefix + date_string
    if len(string_prefix) == len('You have selected: '):
        return 'Select a date to see it displayed here'

if __name__ == '__main__':
    app.run_server(debug=True)

I think you can use waitress to serve in production under Win. https://github.com/Pylons/waitress

You just need to add server = app.server in app.py and create a file server.py that looks like this:

from waitress import serve

from app import server

serve(server)

then you just call python server.py instead of app.py from command line.

Thank you, I will try your suggestion next week!

This was a great help, thank you!
I have now removed all Flask from my IIS deployed apps, which are now using waitress. :slight_smile:

My initial impression is that my app should operate faster now, but I need to run some tests before I can conclude anything definitive. :man_technologist:

I have tried you suggestion and it seems to be working - this is exactly what I was looking for, Thank You!