Problem: I containerized a shiny application with Shiny server pro and docker. Similar to here: https://support.rstudio.com/hc/en-us/articles/360009986893-Shiny-Server-Pro-with-Docker
Question: How can I pass environment variables during run-time to the docker container such that those environment variables can be used in the app (example app below).
The docker command used is:
docker run -it --rm -p 3838:3838 -e env_variable_interest=testname <shiny_image>
, i.e. the variable env_variable_interest is not shown/recognized/transferred in Shiny server.
Many thanks for comments!!
library(shiny)
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
))
)
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white', main = Sys.getenv("env_variable_interest"))
})
}
# Run the application
shinyApp(ui = ui, server = server)