-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Peter Solymos <psolymos@gmail.com>
- Loading branch information
Showing
9 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Rhino / shinyApp entrypoint. Do not edit. | ||
rhino::app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sass: node |