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)