Deploy app in Naas
Tags: #dashboard #plotly #dash #naas #asset #automation #analytics
Description: This notebook provides a step-by-step guide to deploying an app with Dash on Naas.
import os
try:
import dash
except:
!pip install dash --user
import dash
try:
import dash_bootstrap_components as dbc
except:
!pip install dash_bootstrap_components --user
import dash_bootstrap_components as dbc
from dash import html, dcc
import plotly.express as px
import plotly.graph_objects as go
DASH_PORT = 8050
app = dash.Dash(
requests_pathname_prefix=f'/user/{os.environ.get("JUPYTERHUB_USER")}/proxy/{DASH_PORT}/',
external_stylesheets=[dbc.themes.BOOTSTRAP],
meta_tags=[
{"name": "viewport", "content": "width=device-width, initial-scale=1.0"}
],
)
# app = dash.Dash() if you are not in Naas
df = px.data.stocks() # reading stock price dataset
print("Data fetched:", len(df))
df.head(1)
def stock_prices(ticker, label):
# Function for creating line chart showing Google stock prices over time
fig = go.Figure(
[
go.Scatter(
x=df["date"],
y=df[ticker],
line=dict(color="firebrick", width=4),
name=label,
)
]
)
fig.update_layout(
title="Prices over time", xaxis_title="Dates", yaxis_title="Prices"
)
return fig
fig = stock_prices(ticker="GOOG", label="Google")
fig
app.layout = html.Div(
id="parent",
children=[
html.H1(
id="H1",
children="Deploy a Dash app in Naas",
style={"textAlign": "center", "marginTop": 40, "marginBottom": 40},
),
dcc.Graph(id="line_plot", figure=fig),
],
)
if __name__ == "__main__":
app.run_server(proxy=f"http://127.0.0.1:{DASH_PORT}::https://app.naas.ai")
Last modified 1mo ago