From de0a5f72beb1e6341d82682cbbc14393762f8bc7 Mon Sep 17 00:00:00 2001 From: neelasha23 Date: Mon, 13 May 2024 15:18:18 +0530 Subject: [PATCH 1/5] dash --- doc/apps/dash.md | 11 +++++- examples/dash/app-with-auth0/app.py | 34 +++++++++++++++++++ examples/dash/app-with-auth0/requirements.txt | 2 ++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 examples/dash/app-with-auth0/app.py create mode 100644 examples/dash/app-with-auth0/requirements.txt diff --git a/doc/apps/dash.md b/doc/apps/dash.md index dc5d181f..7af9194d 100644 --- a/doc/apps/dash.md +++ b/doc/apps/dash.md @@ -107,13 +107,22 @@ ploomber-cloud deploy --watch To ensure your app doesn't break on re-deployments, pin your [dependencies.](pin-dependencies) ``` +## Production deployments + +Ploomber has features to help you deploy production-ready Dash apps + +### Authentication + +Our [integration with Auth0](auth0-integration) allows you to easily add authentication +to any Dash app. There's no need to modify your Dash app code, only pass your +Auth0 configuration parameters. Check out the [sample app.](https://github.com/ploomber/doc/tree/main/examples/dash/app-with-auth0) + ## Features Ploomber Cloud supports many features to help you build Dash applications quickly! - Integration with [GitHub](../user-guide/github.md) - Safely store [secrets](../user-guide/secrets.md) such as API keys -- Add [password protection](../user-guide/password.md) to your app - Usage [analytics](../user-guide/analytics.md) such as unique visitors, total requests, etc. - Spin up [larger resources](../user-guide/resources.md) (CPUs and RAM) - Spin up [GPUs](../user-guide/gpu.md) diff --git a/examples/dash/app-with-auth0/app.py b/examples/dash/app-with-auth0/app.py new file mode 100644 index 00000000..afa008df --- /dev/null +++ b/examples/dash/app-with-auth0/app.py @@ -0,0 +1,34 @@ +from dash import dcc, html, Input, Output, Dash +from flask import request + +app = Dash(__name__) +server = app.server + +app.layout = html.Div(children=[ + html.Div(id="greeting"), + html.Div(id="logout-link", children=[ + dcc.Markdown(id="logout-msg"), + dcc.Link("Logout", href="/logout") + ]), + html.Div(id="dummy"), + dcc.Graph( + id='example-graph', + figure={ + 'data': [ + {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'Category 1'}, + {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': 'Category 2'}, + ], + 'layout': { + 'title': 'Dash Data Visualization' + } + } + ), + +]) + + +@app.callback(Output("greeting", "children"), Input("dummy", "children")) +def display_user(_): + user = request.headers.get('X-Auth-Name', 'Anonymous') + return f"Welcome {user}!" + diff --git a/examples/dash/app-with-auth0/requirements.txt b/examples/dash/app-with-auth0/requirements.txt new file mode 100644 index 00000000..1429327a --- /dev/null +++ b/examples/dash/app-with-auth0/requirements.txt @@ -0,0 +1,2 @@ +dash +gunicorn \ No newline at end of file From f3b820144e4aef6e0df9f435f723369bf4ab6009 Mon Sep 17 00:00:00 2001 From: neelasha23 Date: Mon, 13 May 2024 18:08:52 +0530 Subject: [PATCH 2/5] chainlit --- examples/chainlit/app-with-auth0/Dockerfile | 7 +++++++ examples/chainlit/app-with-auth0/app.py | 15 +++++++++++++++ examples/chainlit/app-with-auth0/chainlit.md | 1 + 3 files changed, 23 insertions(+) create mode 100644 examples/chainlit/app-with-auth0/Dockerfile create mode 100644 examples/chainlit/app-with-auth0/app.py create mode 100644 examples/chainlit/app-with-auth0/chainlit.md diff --git a/examples/chainlit/app-with-auth0/Dockerfile b/examples/chainlit/app-with-auth0/Dockerfile new file mode 100644 index 00000000..e3c2e2e8 --- /dev/null +++ b/examples/chainlit/app-with-auth0/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11 + +COPY app.py app.py +COPY chainlit.md chainlit.md +RUN pip install chainlit --no-cache-dir + +ENTRYPOINT ["chainlit", "run", "app.py", "--host=0.0.0.0", "--port=80", "--headless"] \ No newline at end of file diff --git a/examples/chainlit/app-with-auth0/app.py b/examples/chainlit/app-with-auth0/app.py new file mode 100644 index 00000000..435d2c22 --- /dev/null +++ b/examples/chainlit/app-with-auth0/app.py @@ -0,0 +1,15 @@ +from typing import Optional + +import chainlit as cl + + +@cl.header_auth_callback +def header_auth_callback(headers: dict) -> Optional[cl.User]: + return cl.User(identifier=headers.get("X-Auth-Name", "Anonymous"), + metadata={"role": "admin", "provider": "header"}) + + +@cl.on_message +async def on_message(message: cl.Message): + response = f"Hello, you just sent: {message.content}!" + await cl.Message(response).send() diff --git a/examples/chainlit/app-with-auth0/chainlit.md b/examples/chainlit/app-with-auth0/chainlit.md new file mode 100644 index 00000000..df93e612 --- /dev/null +++ b/examples/chainlit/app-with-auth0/chainlit.md @@ -0,0 +1 @@ +This app is hosted in [Ploomber Cloud!](https://ploomber.io/) \ No newline at end of file From 3ccad1f8210a5dc8e37d854e73a8c81307ba6cde Mon Sep 17 00:00:00 2001 From: neelasha23 Date: Mon, 13 May 2024 18:12:37 +0530 Subject: [PATCH 3/5] docs --- doc/apps/chainlit.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/apps/chainlit.md b/doc/apps/chainlit.md index 3fdd31e5..372b2ce3 100644 --- a/doc/apps/chainlit.md +++ b/doc/apps/chainlit.md @@ -64,13 +64,23 @@ To deploy a Chainlit app from the deployment menu, follow these instructions: To ensure your app doesn't break on re-deployments, pin your [dependencies.](pin-dependencies) ``` +## Production deployments + +Ploomber has features to help you deploy production-ready Chainlit apps + +### Authentication + +Our [integration with Auth0](auth0-integration) allows you to easily add authentication +to any Chainlit app. There's no need to modify your Chainlit app code, only pass your +Auth0 configuration parameters. Check out the [sample app.](https://github.com/ploomber/doc/tree/main/examples/chainlit/app-with-auth0). +In addition to the Auth0 parameters you also need to pass the `CHAINLIT_AUTH_SECRET` value. Refer to [chainlit-pwd]((chainlit-password) to learn more. + ## Features Ploomber Cloud supports many features to help you build Streamlit applications quickly! - Integration with [GitHub](../user-guide/github.md) - Safely store [secrets](../user-guide/secrets.md) such as API keys -- Add [password protection](chainlit-password) to your app - Usage [analytics](../user-guide/analytics.md) such as unique visitors, total requests, etc. - Spin up [larger resources](../user-guide/resources.md) (CPUs and RAM) - Spin up [GPUs](../user-guide/gpu.md) From 4185fcaabc481a18e7d346ff3ee589fd14382c8c Mon Sep 17 00:00:00 2001 From: neelasha23 Date: Mon, 13 May 2024 18:34:57 +0530 Subject: [PATCH 4/5] typo --- doc/apps/chainlit.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/apps/chainlit.md b/doc/apps/chainlit.md index 372b2ce3..b1513ed2 100644 --- a/doc/apps/chainlit.md +++ b/doc/apps/chainlit.md @@ -72,8 +72,8 @@ Ploomber has features to help you deploy production-ready Chainlit apps Our [integration with Auth0](auth0-integration) allows you to easily add authentication to any Chainlit app. There's no need to modify your Chainlit app code, only pass your -Auth0 configuration parameters. Check out the [sample app.](https://github.com/ploomber/doc/tree/main/examples/chainlit/app-with-auth0). -In addition to the Auth0 parameters you also need to pass the `CHAINLIT_AUTH_SECRET` value. Refer to [chainlit-pwd]((chainlit-password) to learn more. +Auth0 configuration parameters. Check out the [sample app.](https://github.com/ploomber/doc/tree/main/examples/chainlit/app-with-auth0) +In addition to the Auth0 parameters you also need to pass the `CHAINLIT_AUTH_SECRET` value. Refer to [chainlit-pwd](chainlit-password) to learn more. ## Features From dddee928c396c4ba7fd0cbf0bde6b52592604afb Mon Sep 17 00:00:00 2001 From: neelasha23 Date: Mon, 13 May 2024 18:39:25 +0530 Subject: [PATCH 5/5] typo --- doc/apps/chainlit.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/apps/chainlit.md b/doc/apps/chainlit.md index b1513ed2..10798923 100644 --- a/doc/apps/chainlit.md +++ b/doc/apps/chainlit.md @@ -73,7 +73,7 @@ Ploomber has features to help you deploy production-ready Chainlit apps Our [integration with Auth0](auth0-integration) allows you to easily add authentication to any Chainlit app. There's no need to modify your Chainlit app code, only pass your Auth0 configuration parameters. Check out the [sample app.](https://github.com/ploomber/doc/tree/main/examples/chainlit/app-with-auth0) -In addition to the Auth0 parameters you also need to pass the `CHAINLIT_AUTH_SECRET` value. Refer to [chainlit-pwd](chainlit-password) to learn more. +In addition to the Auth0 parameters you also need to pass the `CHAINLIT_AUTH_SECRET` value. Refer to [this section](chainlit-password) to learn more. ## Features