✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
📊 Dash 2.0 is Arriving. Register here.

Form Submission and Routing to New Page

I’m trying to create a form with multiple kinds of inputs. I would like to save these inputs into a Pandas Dataframe and eventually write it into a PostgreSQL database on clicking the Submit Button. I would also like to re-route to a new page containing an editable dash table containing values read from another PostgreSQL table.

I’m new to Dash but I’m working on a great project. Would appreciate any help!

Thanks!

Work around:

html.A(html.Button(‘Submit!’, id=‘submit’),
href=’/apps/app2’),

Also, I would like to know how to implement the Clear Form functionality where all the inputs are refreshed to defaults on button press.

You can do a regular form with dash html components, then add a route to the flask server to handle the form submission.

Basic example:

import flask
import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash(__name__)

app.layout = html.Form([
    dcc.Input(name='name'),
    html.Button('Submit', type='submit')
], action='/post', method='post')


@app.server.route('/post', methods=['POST'])
def on_post():
    data = flask.request.form
    print(data)
    return flask.redirect('/')


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

You can clear form with a html.Button('clear', type='clear').