[Bug]: shiny.router does not work when deploying a shiny app in docker
Closed this issue · 1 comments
jaahumadap commented
Guidelines
- I agree to follow this project's Contributing Guidelines.
Project Version
0.2.3
Platform and OS Version
macOS 13.0.1
Existing Issues
No response
What happened?
Deployed a simple shiny app that uses shiny.router to display two pages. I deployed a docker container locally to test (because eventually want to deployed in Cloud Run). However, the app does not run.
Steps to reproduce
- Wrote simple shiny app that displays two pages. You can change pages by pressing a button.
- Build a container locally in docker: e.g.
docker build -t shinyrouter .
- Run it: e.g.
docker run -d -p 3838:3838 shinyrouter
- Open a browser and type http://localhost:3838
...
Expected behavior
Attachments
Shiny app code:
library(shiny)
library(shiny.router)
library(DT)
# This is where the UI of page 1 is specified
home_page <- div(
titlePanel("Home page"),
p("This is the home page!"),
plotOutput("graph"),
fluidRow(
column(12,
align = "right",
actionButton("next_page", "Next")
)
)
)
# This is where the UI of page 2 is specified
another_page <- div(
titlePanel("Another page"),
p("This is the another page!"),
DTOutput("table"),
fluidRow(
column(12,
align = "right",
actionButton("prev_page", "Back to Main")
)
),
verbatimTextOutput("rows")
)
#this connects each page with an HTML address
router <- make_router(
route("/", home_page, NA),
route("another", another_page, NA)
)
# This is where it is all put together - only need to point to the router
ui <- fluidPage(
router$ui
)
server <- function(input, output, session) {
# important to add this line in the server function
router$server(input, output, session)
# When the button is clicked in page 1 go to page 2
observeEvent(input$next_page,
change_page("another")
)
# When the button is clicked on page 2 go back to page 1
observeEvent(input$prev_page,
change_page("/")
)
# other functions on the server side
output$graph <- renderPlot({
x <- runif(100)
y <- runif(100)
plot(x, y)
})
output$table <- renderDT({
iris
})
# get specific rows from the table and extract the specific value
output$rows = renderPrint({
s <- input$table_rows_selected
if (length(s)) {
print(iris[s, "Sepal.Width"], sep = '\n')
}
})
}
shinyApp(ui, server)
Dockerfile:
FROM rocker/shiny-verse:4.2.2
# system libraries of general use
RUN apt-get update && apt-get install -y \
libcurl4-gnutls-dev \
libssl-dev
RUN install2.r --deps TRUE --ncpus -1 shiny.router
# copy the app to the image
COPY app.R /srv/shiny-server/app.R
#RUN chmod +x /srv/shiny-server/shiny-server.sh
# select port
EXPOSE 3838
# allow permission
RUN sudo chown -R shiny:shiny /srv/shiny-server
# run app
CMD ["/usr/bin/shiny-server"]
Screenshots or Videos
Additional Information
No response
jaahumadap commented
never mind.. was missing a package (DT) in my Dockerfile