Skip to main content

Dash

Setting up a Dash Live App on MINEO is a hassle-free way to deploy interactive web applications. Follow these steps to create your own Dash Live App:

Step 1: Create the app.py File​

Begin by creating a file named app.py in your project directory. Remember, the paths mentioned in the entrypoint command are relative to the Live App's folder. This file will contain the code for your Dash application. Here’s a simple example to get you started:

import os
import dash
from dash import dcc, html
import pandas as pd
import plotly.graph_objs as go

data = {
"Year": [1950, 1960, 1970, 1980, 1990, 2000, 2010, 2020],
"Population": [2.5, 3.0, 3.7, 4.4, 5.3, 6.1, 6.9, 7.8],
}
df = pd.DataFrame(data)

root_path = os.environ.get("MINEO_LIVE_APP_URL_PATH")
if not root_path:
raise RuntimeError("The MINEO_LIVE_APP_URL_PATH environment variable is not defined.")

app = dash.Dash(__name__, routes_pathname_prefix="/", requests_pathname_prefix=root_path)
app.layout = html.Div(
[
html.H1("🌍 World Population Growth", style={"textAlign": "center"}),
dcc.Graph(
id="pop-chart",
figure={
"data": [
go.Scatter(
x=df["Year"],
y=df["Population"],
mode="lines+markers",
name="Population",
line=dict(color="blue"),
marker=dict(size=10),
)
],
"layout": go.Layout(
xaxis=dict(title="Year"),
yaxis=dict(title="Population (Billions)"),
hovermode="closest",
template="plotly_dark",
),
},
),
]
)
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=8000)

This Dash app displays a simple graph of world population growth. Feel free to add more features as needed.

Step 2: Set Up a New Live App​

Next, you need to configure a new Live App on MINEO and define an entrypoint command to launch your application.

Here's the basic structure for the entrypoint command:

pip install dash pandas plotly && python app.py

Adding Dependencies​

If your app requires additional packages, you have two methods to include them:

  1. Direct pip install: Include the required packages in the entrypoint command.

    pip install dash pandas plotly && python app.py
  2. Using requirements.txt: List your dependencies in a requirements.txt file and reference it in the entrypoint command.

    pip install -r requirements.txt --no-cache-dir && python app.py

Example requirements.txt:

dash
pandas
plotly

Configuration Needed to Share Your App​

Important Launch Settings​

To ensure your Dash app is accessible via MINEO, make sure to configure the following settings:

  • Host: Set host to "0.0.0.0" to allow external access.
  • Port: Use port=8000.
  • Routing: Ensure routes_pathname_prefix="/" and use the environment variable MINEO_LIVE_APP_URL_PATH as the requests_pathname_prefix.
root_path = os.environ.get("MINEO_LIVE_APP_URL_PATH")
app = dash.Dash(__name__, routes_pathname_prefix="/", requests_pathname_prefix=root_path)

The environment variable MINEO_LIVE_APP_URL_PATH contains the correct routing path.

Launch and Share Your Live App​

Once your app.py and entrypoint command are ready, use the Execute button to deploy your Dash application and make it accessible.

Now you can share your Live App URL and develop in a stable, secure environment on the MINEO platform. Enjoy your Dash Live App!