diff --git a/examples/docker/fastHTML/Dockerfile b/examples/docker/fastHTML/Dockerfile new file mode 100644 index 00000000..3fb4dc30 --- /dev/null +++ b/examples/docker/fastHTML/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.11 + +RUN apt-get update + +COPY . /app + +WORKDIR /app + +RUN pip install -r requirements.txt --no-cache-dir + +ENTRYPOINT ["uvicorn", "app:app", "--host=0.0.0.0", "--port=80"] diff --git a/examples/docker/fastHTML/README.md b/examples/docker/fastHTML/README.md new file mode 100644 index 00000000..f7506810 --- /dev/null +++ b/examples/docker/fastHTML/README.md @@ -0,0 +1,5 @@ +# Docker Deployment with FastHTML App + +Example Dockerfile and FastHTML app to deploy on Ploomber Cloud. The fastHTML app code was obtained from the [FastHTML examples repository](https://github.com/AnswerDotAI/fasthtml/tree/main/examples). This app is a basic todo list item tracker. To deploy your own fastHTML app, replace the `app.py` code with your code and add any Python libraries used to `requirements.txt`. + +![](todolist_app.png) \ No newline at end of file diff --git a/examples/docker/fastHTML/app.py b/examples/docker/fastHTML/app.py new file mode 100644 index 00000000..1fefdc2b --- /dev/null +++ b/examples/docker/fastHTML/app.py @@ -0,0 +1,46 @@ +# This example was obtained from FastHTML's examples directory. You can check it out here: https://github.com/AnswerDotAI/fasthtml/blob/main/examples/basic_app.py + +# Run with: python basic_app.py +from fasthtml.common import * + +def render(todo): + show = AX(todo.title, f'/todos/{todo.id}', 'current-todo') + edit = AX('edit', f'/edit/{todo.id}' , 'current-todo') + dt = ' (done)' if todo.done else '' + return Li(show, dt, ' | ', edit, id=f'todo-{todo.id}') + +app,rt,todos,Todo = fast_app('data/todos.db', render, id=int, title=str, done=bool, pk='id') + +@rt("/") +def get(): + inp = Input(id="new-title", name="title", placeholder="New Todo") + add = Form(Group(inp, Button("Add")), hx_post="/", target_id='todo-list', hx_swap="beforeend") + card = Card(Ul(*todos(), id='todo-list'), header=add, footer=Div(id='current-todo')), + return Titled('Todo list', card) + +@rt("/") +def post(todo:Todo): + return todos.insert(todo), Input(id="new-title", name="title", placeholder="New Todo", hx_swap_oob='true') + +@rt("/edit/{id}") +def get(id:int): + res = Form(Group(Input(id="title"), Button("Save")), + Hidden(id="id"), CheckboxX(id="done", label='Done'), + hx_put="/", target_id=f'todo-{id}', id="edit") + return fill_form(res, todos[id]) + +@rt("/") +def put(todo: Todo): return todos.upsert(todo), clear('current-todo') + +@rt("/todos/{id}") +def get(id:int): + todo = todos[id] + btn = Button('delete', hx_delete=f'/todos/{todo.id}', target_id=f'todo-{id}', hx_swap="outerHTML") + return Div(Div(todo.title), btn) + +@rt("/todos/{id}") +def delete(id:int): + todos.delete(id) + return clear('current-todo') + +serve() \ No newline at end of file diff --git a/examples/docker/fastHTML/app.zip b/examples/docker/fastHTML/app.zip new file mode 100644 index 00000000..b41a7ffb Binary files /dev/null and b/examples/docker/fastHTML/app.zip differ diff --git a/examples/docker/fastHTML/requirements.txt b/examples/docker/fastHTML/requirements.txt new file mode 100644 index 00000000..c5f7ff3a --- /dev/null +++ b/examples/docker/fastHTML/requirements.txt @@ -0,0 +1 @@ +python-fasthtml \ No newline at end of file diff --git a/examples/docker/fastHTML/todolist_app.png b/examples/docker/fastHTML/todolist_app.png new file mode 100644 index 00000000..551eefba Binary files /dev/null and b/examples/docker/fastHTML/todolist_app.png differ diff --git a/examples/streamlit/postgres-connection/app.zip b/examples/streamlit/postgres-connection/app.zip new file mode 100644 index 00000000..338eefd3 Binary files /dev/null and b/examples/streamlit/postgres-connection/app.zip differ