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...
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:
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 itschildrenparameter. This will produce anH1element on the page. - Lines 7-8: We run the app. Note that we set
debug=Truein theapp.run_servermethod. 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 running:
A working example has been set up below:
import dash
import dash_html_components as html
app = dash.Dash(__name__)
app.layout = html.Div([
html.H1('Hello, World!')
])
if __name__ == '__main__':
app.run_server(host='0.0.0.0', debug=True, port=8050)Running the simplest Dash application
Congratulations on ...