Creating and Running a Simple App
Follow step-by-step instructions to create and run a simple application in Python using Dash.
We'll cover the following...
Let’s build our first simple app! We’ll start with the app.py
file.
Steps to create and run the app
Create a file, name it app.py
, and write the following code:
Press + to interact
import dashimport dash_html_components as htmlapp = dash.Dash(__name__)app.layout = html.Div([html.H1('Hello, World!')])if __name__ == '__main__':app.run_server(debug=True)
- Lines 1–2: We import the required packages using their usual aliases.
- Line 3: We instantiate the app.
- Lines 4–6: We create the app’s layout. This app’s layout contains one element—the list passed to
html.Div
, which corresponds to itschildren
parameter. This will produce anH1
element on the page. - Lines 7-8: We run the app. Note that we set
debug=True
in theapp.run_server
method. This activates several developer tools that are really useful while developing and debugging.
Running example
We’re now ready to run our first app. Go ahead and click the “Run” button. You should now see an output like the one shown in the illustration below, which indicates that the app is ...