Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dash, Chainlit auth0 example #222

Merged
merged 5 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion doc/apps/chainlit.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [this section](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)
Expand Down
11 changes: 10 additions & 1 deletion doc/apps/dash.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions examples/chainlit/app-with-auth0/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
15 changes: 15 additions & 0 deletions examples/chainlit/app-with-auth0/app.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions examples/chainlit/app-with-auth0/chainlit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This app is hosted in [Ploomber Cloud!](https://ploomber.io/)
34 changes: 34 additions & 0 deletions examples/dash/app-with-auth0/app.py
Original file line number Diff line number Diff line change
@@ -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}!"

2 changes: 2 additions & 0 deletions examples/dash/app-with-auth0/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dash
gunicorn