Skip to content

Commit

Permalink
Add quarto
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Solymos <psolymos@gmail.com>
  • Loading branch information
psolymos committed Jul 6, 2024
1 parent 98216a7 commit 7b72cd5
Show file tree
Hide file tree
Showing 61 changed files with 15,076 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/quarto-py-shiny.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build and Push Docker Image for faithful/quarto-py-shiny

on:
push:
branches: [ "main" ]
paths: [ "quarto-py-shiny/**"]
pull_request:
branches: [ "main" ]
paths: [ "quarto-py-shiny/**"]

env:
SHINY_SETUP: quarto-py-shiny

permissions:
packages: write

jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:

- name: 'Checkout GitHub Action'
uses: actions/checkout@v4

- name: 'Docker metadata'
id: meta
uses: docker/metadata-action@v5
with:
labels: |
maintainer=Peter Solymos
org.opencontainers.image.title=Faithful
org.opencontainers.image.description=Old Faithful Shiny app
org.opencontainers.image.vendor=Hosting Shiny Book Project
images: |
ghcr.io/${{ github.repository }}/${{ env.SHINY_SETUP }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=ref,event=pr
- name: 'Login to GitHub Container Registry'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: 'Build and push'
uses: docker/build-push-action@v6
with:
context: ./${{ env.SHINY_SETUP }}
file: ./${{ env.SHINY_SETUP }}/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
58 changes: 58 additions & 0 deletions .github/workflows/quarto-r-shiny-multifile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build and Push Docker Image for faithful/quarto-r-shiny-multifile

on:
push:
branches: [ "main" ]
paths: [ "quarto-r-shiny-multifile/**"]
pull_request:
branches: [ "main" ]
paths: [ "quarto-r-shiny-multifile/**"]

env:
SHINY_SETUP: quarto-r-shiny-multifile

permissions:
packages: write

jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:

- name: 'Checkout GitHub Action'
uses: actions/checkout@v4

- name: 'Docker metadata'
id: meta
uses: docker/metadata-action@v5
with:
labels: |
maintainer=Peter Solymos
org.opencontainers.image.title=Faithful
org.opencontainers.image.description=Old Faithful Shiny app
org.opencontainers.image.vendor=Hosting Shiny Book Project
images: |
ghcr.io/${{ github.repository }}/${{ env.SHINY_SETUP }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=ref,event=pr
- name: 'Login to GitHub Container Registry'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: 'Build and push'
uses: docker/build-push-action@v6
with:
context: ./${{ env.SHINY_SETUP }}
file: ./${{ env.SHINY_SETUP }}/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
58 changes: 58 additions & 0 deletions .github/workflows/quarto-r-shiny.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build and Push Docker Image for faithful/quarto-r-shiny

on:
push:
branches: [ "main" ]
paths: [ "quarto-r-shiny/**"]
pull_request:
branches: [ "main" ]
paths: [ "quarto-r-shiny/**"]

env:
SHINY_SETUP: quarto-r-shiny

permissions:
packages: write

jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:

- name: 'Checkout GitHub Action'
uses: actions/checkout@v4

- name: 'Docker metadata'
id: meta
uses: docker/metadata-action@v5
with:
labels: |
maintainer=Peter Solymos
org.opencontainers.image.title=Faithful
org.opencontainers.image.description=Old Faithful Shiny app
org.opencontainers.image.vendor=Hosting Shiny Book Project
images: |
ghcr.io/${{ github.repository }}/${{ env.SHINY_SETUP }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=ref,event=pr
- name: 'Login to GitHub Container Registry'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: 'Build and push'
uses: docker/build-push-action@v6
with:
context: ./${{ env.SHINY_SETUP }}
file: ./${{ env.SHINY_SETUP }}/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
38 changes: 38 additions & 0 deletions quarto-py-shiny/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Define the parent image
FROM python:3.9

# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
pandoc \
curl \
gdebi-core \
&& rm -rf /var/lib/apt/lists/*
RUN curl -LO https://quarto.org/download/latest/quarto-linux-amd64.deb
RUN gdebi --non-interactive quarto-linux-amd64.deb
RUN gdebi --non-interactive quarto-linux-amd64.deb
COPY app/requirements.txt .
RUN pip install --no-cache-dir --upgrade -r requirements.txt

# Add non-root user and group
RUN groupadd app && useradd -g app app

# Set working directory to home of the non-root user
WORKDIR /home/app

# Copy Shiny app files
COPY app .

# Prerender document
RUN quarto render index.qmd

# Set owner for the home folder
RUN chown app:app -R /home/app

# Set user to non-root
USER app

# Expose port
EXPOSE 3838

# Set command to execute at runtime
CMD ["quarto", "serve", "index.qmd", "--port", "3838", "--host", "0.0.0.0", "--no-render"]
41 changes: 41 additions & 0 deletions quarto-py-shiny/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Quarto with Python

Server `shiny`

```bash
cd quarto-py-shiny/app
quarto serve index.qmd --port 8080
```

Server `shiny`, prerendered.

```bash
quarto render index.qmd
quarto serve index.qmd --port 8080 --no-render
```

Pull and run Docker image:

```bash
docker pull ghcr.io/h10y/faithful/quarto-py-shiny:latest
docker run -p 8080:3838 ghcr.io/h10y/faithful/quarto-py-shiny:latest
```

Containerized version:

```bash
# Change directory
cd quarto-py-shiny

# If on MacOS X, set this
export DOCKER_DEFAULT_PLATFORM=linux/amd64

# Specify tag
export TAG=faithful/quarto-py-shiny:latest

# Build image
docker build -t $TAG .

# Run image, visit http://localhost:8080
docker run --rm -p 8080:3838 $TAG
```
Binary file not shown.
58 changes: 58 additions & 0 deletions quarto-py-shiny/app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# This file generated by Quarto; do not edit by hand.
# shiny_mode: core

from __future__ import annotations

from pathlib import Path
from shiny import App, Inputs, Outputs, Session, ui




def server(input: Inputs, output: Outputs, session: Session) -> None:
import seaborn as sns
import matplotlib.pyplot as plt
from shiny import App, render, ui

faithful = sns.load_dataset("geyser")
x = faithful.waiting

# ========================================================================

ui.input_slider(
id="n",
label="Number of bins:",
min=1,
max=50,
value=25,
ticks=True)

# ========================================================================

@render.plot(alt="Histogram of waiting times")
def histogram():
plt.hist(
x,
bins = input.n(),
density=False,
color="#BB74DB",
edgecolor="white")
plt.title("Histogram of waiting times")
plt.xlabel("Waiting time to next eruption [mins]")
plt.ylabel("Frequency")

# ========================================================================



return None


_static_assets = ["index_files","index_files/libs/quarto-html/tippy.css","index_files/libs/quarto-html/quarto-syntax-highlighting.css","index_files/libs/bootstrap/bootstrap-icons.css","index_files/libs/bootstrap/bootstrap.min.css","index_files/libs/clipboard/clipboard.min.js","index_files/libs/quarto-html/quarto.js","index_files/libs/quarto-html/popper.min.js","index_files/libs/quarto-html/tippy.umd.min.js","index_files/libs/quarto-html/anchor.min.js","index_files/libs/bootstrap/bootstrap.min.js"]
_static_assets = {"/" + sa: Path(__file__).parent / sa for sa in _static_assets}

app = App(
Path(__file__).parent / "index.html",
server,
static_assets=_static_assets,
)
Loading

0 comments on commit 7b72cd5

Please sign in to comment.