generated from SwissDataScienceCenter/sdsc-2024-10-ord-hackathon-template
-
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.
- Loading branch information
Showing
4 changed files
with
98 additions
and
8 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
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 |
---|---|---|
@@ -1,18 +1,57 @@ | ||
# Shiny Serving Demo | ||
|
||
This is a demo project that serves a Shiny app from a Renku V2 project. | ||
This is a demo project that shows how to serve a Shiny app from a Renku V2 project. It uses the [rocker shiny](https://rocker-project.org/images/versioned/shiny.html) Docker base image and makes some modifications necessary for compatibility with Renku sessions. | ||
|
||
To use it, you can create a Renku V2 launcher that references the image URL in the project package. You need to also set the following settings: | ||
You can see it in action at https://renkulab.io/v2/projects/cramakri/shiny-demo. | ||
|
||
- user id: 999 (the `shiny` user in the Rocker image) | ||
- port: 3838 | ||
## Serving your own shiny app | ||
|
||
This project serves a "hello-world" Shiny example app. To serve your own app, you can clone this repo, add your app, and then configure a Renku V2 session launcher. | ||
|
||
### Adding your app | ||
|
||
Once you have cloned this repo, you can replace the code in the `src/r/app` folder with your app. | ||
|
||
After doing that, you should build the image and test that the app works. This requires Docker installed on your machine, but it will help you debug problems quickly. | ||
|
||
For example, you can build and run with the following commands: | ||
|
||
``` | ||
docker buildx build -t renku/shiny-session --platform linux/amd64 . | ||
docker run --rm -ti -e RENKU_BASE_URL_PATH="/test-app" -p 3838:3838 renku/shiny-session | ||
``` | ||
|
||
If everything worked correctly, you should be able to connect a web browser to | ||
|
||
http://localhost:3838/test-app/ | ||
|
||
And you should see your app there. | ||
|
||
|
||
### Renku session launcher | ||
|
||
Once your app runs locally, you can serve it from Renku. To do this, you will need to create a session launcher with the following pieces of information: | ||
|
||
- the container image URL | ||
- the port | ||
- UID and GID for the container | ||
|
||
This repo is configured to build a Docker image. You should see a section called **Packages** in the right-hand side of the page for this repo. Click there to get the URL for the image (you will probably want to most recent one). | ||
|
||
It will look something like: `ghcr.io/swissdatasciencecenter/demo-shiny-serve:sha-1478fc5` | ||
|
||
The other pieces of information are fixed: | ||
|
||
- Port: 3838 | ||
- UID: 997 (the `shiny` user in the Rocker image) | ||
- GID: 997 | ||
|
||
With that, you should have a session launcher that serves your Shiny app from Renku! | ||
|
||
## References | ||
|
||
This project builds on The Rocker Shiny which builds a Docker image containing the Shiny Server. | ||
This project builds on The Rocker Shiny Docker image, which is designed to run the Shiny Server. Here are links to documentation for the Rocker image and Shiny Server. You may find them helpful for more advanced use cases. | ||
|
||
- https://rocker-project.org/images/versioned/shiny.html | ||
- https://posit.co/download/shiny-server/ | ||
- https://docs.posit.co/shiny-server/ | ||
- https://github.com/rstudio/shiny-server/ |
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
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,47 @@ | ||
library(shiny) | ||
library(bslib) | ||
|
||
# Define UI for app that draws a histogram ---- | ||
ui <- page_sidebar( | ||
# App title ---- | ||
title = "Hello Shiny/Renku!", | ||
# Sidebar panel for inputs ---- | ||
sidebar = sidebar( | ||
# Input: Slider for the number of bins ---- | ||
sliderInput( | ||
inputId = "bins", | ||
label = "Number of bins:", | ||
min = 1, | ||
max = 50, | ||
value = 30 | ||
) | ||
), | ||
# Output: Histogram ---- | ||
plotOutput(outputId = "distPlot") | ||
) | ||
|
||
# Define server logic required to draw a histogram ---- | ||
server <- function(input, output) { | ||
|
||
# Histogram of the Old Faithful Geyser Data ---- | ||
# with requested number of bins | ||
# This expression that generates a histogram is wrapped in a call | ||
# to renderPlot to indicate that: | ||
# | ||
# 1. It is "reactive" and therefore should be automatically | ||
# re-executed when inputs (input$bins) change | ||
# 2. Its output type is a plot | ||
output$distPlot <- renderPlot({ | ||
|
||
x <- faithful$waiting | ||
bins <- seq(min(x), max(x), length.out = input$bins + 1) | ||
|
||
hist(x, breaks = bins, col = "#007bc2", border = "white", | ||
xlab = "Waiting time to next eruption (in mins)", | ||
main = "Histogram of waiting times") | ||
|
||
}) | ||
|
||
} | ||
|
||
shinyApp(ui = ui, server = server) |