Last active
April 9, 2025 02:23
-
-
Save arraytools/08f9d0ba651b504176d77fbeab72e501 to your computer and use it in GitHub Desktop.
R shiny application with non-root output. Go to http://localhost:3838/myapp to see the shiny application.
This file contains hidden or 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
$ tree | |
├── app | |
│ └── myapp | |
│ └── app.R | |
└── compose.yml | |
$ mkdir -p app/myapp | |
$ sudo chmod 777 app/myapp # shiny user can write | |
$ docker compose up | |
# Click the 'Write Output File' button | |
$ ls -l app/myapp | |
$ cat app/myapp/output.txt | |
Written at 2025-04-09 02:04:08.826596 |
This file contains hidden or 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
library(shiny) | |
ui <- fluidPage( | |
titlePanel("Write File Example"), | |
actionButton("write_btn", "Write Output File"), | |
verbatimTextOutput("status"), | |
verbatimTextOutput("uid_info") | |
) | |
server <- function(input, output, session) { | |
output$uid_info <- renderPrint({ | |
list( | |
user = Sys.info()[["user"]], | |
uid = system("id -u", intern = TRUE), | |
gid = system("id -g", intern = TRUE), | |
pwd = getwd() | |
) | |
}) | |
observeEvent(input$write_btn, { | |
file_path <- "output.txt" | |
tryCatch({ | |
writeLines(paste("Written at", Sys.time()), file_path) | |
output$status <- renderText(paste("Successfully wrote to:", file_path)) | |
}, error = function(e) { | |
output$status <- renderText(paste("Error:", e$message)) | |
}) | |
}) | |
} | |
shinyApp(ui, server) |
This file contains hidden or 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
services: | |
shiny: | |
image: rocker/shiny | |
ports: | |
- "3838:3838" | |
volumes: | |
- ./app:/srv/shiny-server | |
user: "${UID}:${GID}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment