Skip to content

Commit

Permalink
Add rhiny version
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 5d80ec0 commit 863277b
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/r-rhino.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build and Push Docker Image for faithful/r-rhino

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

env:
SHINY_SETUP: r-rhino

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 }}
29 changes: 29 additions & 0 deletions r-rhino/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Define the parent image
FROM rocker/r2u:24.04

# Install general dependencies
RUN R -q -e "install.packages('deps')"

# 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 rhino-app .

# Install dependencies
RUN R -q -e "deps::install(ask=FALSE)"

# 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 ["R", "-e", "shiny::runApp(host='0.0.0.0', port=3838)"]
32 changes: 32 additions & 0 deletions r-rhino/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## R Shiny as a Rhino app

```bash
cd r-rhino/rhino-app
R -q -e "shiny::runApp(port=8080)"
```

Pull and run Docker image:

```bash
docker pull ghcr.io/h10y/faithful/r-rhino:latest
docker run -p 8080:3838 ghcr.io/h10y/faithful/r-rhino:latest
```

Containerized version:

```bash
# Change directory
cd r-rhino

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

# Specify tag
export TAG=faithful/r-rhino:latest

# Build image
docker build -t $TAG .

# Run image, visit http://localhost:8080
docker run --rm -p 8080:3838 $TAG
```
2 changes: 2 additions & 0 deletions r-rhino/rhino-app/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Rhino / shinyApp entrypoint. Do not edit.
rhino::app()
49 changes: 49 additions & 0 deletions r-rhino/rhino-app/app/main.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
box::use(
shiny[fixedPage, moduleServer, NS, plotOutput, sliderInput, renderPlot, h2],
graphics[hist, box],
datasets[faithful],
)

x <- faithful$waiting

#' @export
ui <- function(id) {
ns <- NS(id)
fixedPage(
title = "Old Faithful",
h2("Old Faithful"),
plotOutput(outputId = ns("histogram")),
sliderInput(
inputId = ns("n"),
label = "Number of bins:",
min = 1,
max = 50,
value = 25,
ticks = TRUE
)
)
}

#' @export
server <- function(id) {
moduleServer(id, function(input, output, session) {
output$histogram <- renderPlot(
alt = "Histogram of waiting times",
{
hist(
x,
breaks = seq(min(x), max(x),
length.out = input$n + 1
),
freq = TRUE,
col = "#BB74DB",
border = "white",
main = "Histogram of waiting times",
xlab = "Waiting time to next eruption [mins]",
ylab = "Frequency"
)
box()
}
)
})
}
Binary file added r-rhino/rhino-app/app/static/favicon.ico
Binary file not shown.
3 changes: 3 additions & 0 deletions r-rhino/rhino-app/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
default:
rhino_log_level: !expr Sys.getenv("RHINO_LOG_LEVEL", "INFO")
rhino_log_file: !expr Sys.getenv("RHINO_LOG_FILE", NA)
2 changes: 2 additions & 0 deletions r-rhino/rhino-app/dependencies.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file allows packrat (used by rsconnect during deployment) to pick up dependencies.
library(rhino)
1 change: 1 addition & 0 deletions r-rhino/rhino-app/rhino.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sass: node

0 comments on commit 863277b

Please sign in to comment.