rstudio / shiny-server

Host Shiny applications over the web.
https://rstudio.com/shiny/server
Other
716 stars 289 forks source link

Unknown Object "port" running Shiny-Server in Docker #491

Open Seyphaton opened 3 years ago

Seyphaton commented 3 years ago

Hey,

I installed shiny-server inside a docker container to host a small app.

Error Message: When I try to start the app I get the following error message:

[2021-07-14T07:44:42.062] [INFO] shiny-server - Error getting worker: Error: The application exited during initialization.
Logging to R console: ENABLED
Logging to JavaScript console: ENABLED
File log doesn't exist.
Your current working directory:
/srv/shiny-server/app
New log file: 'logs/2021-07-14_084441_events.log' has been created.
Logging to the file: ENABLED: logs/2021-07-14_084441_events.log
Logging to a database: disabled
Error in runApp(Sys.getenv("SHINY_APP"), port = port, launch.browser = FALSE) :
object 'port' not found
Execution halted

I assume this error is related to this code: https://github.com/rstudio/shiny-server/blob/da6c4852c4c99189e75f5bc740eac1b199626d70/R/SockJSAdapter.R#L244

However, I am confused about this error message because executing the code in a R console within in docker container (using the shiny user) works just fine and read the correct 'shiny_port'.

Thanks a lot in advance for your help/advise.

My Setup: Dockerfile to build my image:

# Base image https://hub.docker.com/u/rocker/
FROM rocker/shiny:latest

# system libraries of general use
## install debian packages
RUN apt-get update && apt-get install -y \
    sudo \
    gdebi-core \
    pandoc \
    pandoc-citeproc \
    libcairo2-dev \
    libxt-dev \
    libxml2-dev \
    libcairo2-dev \
    libsqlite3-dev \
    libmariadbd-dev \
    libpq-dev \
    libssh2-1-dev \
    unixodbc-dev \
    libcurl4-openssl-dev \
    libssl-dev \
    libsasl2-dev \
    xtail \
    wget

# Prepare permissions to run "run_renv.R" inside shiny-server.sh when the container starts:
WORKDIR /srv/shiny-server/app/
RUN sudo chown shiny /usr/local/lib/R/site-library/
RUN sudo chmod g=rwx /usr/local/lib/R/site-library/ -R

# Download and install shiny server
RUN wget --no-verbose https://download3.rstudio.org/ubuntu-14.04/x86_64/VERSION -O "version.txt" && \
    VERSION=$(cat version.txt)  && \
    wget --no-verbose "https://download3.rstudio.org/ubuntu-14.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \
    gdebi -n ss-latest.deb && \
    rm -f version.txt ss-latest.deb && \
    . /etc/environment && \
    cp -R /usr/local/lib/R/site-library/shiny/examples/* /srv/shiny-server/ && \
    chown shiny:shiny /var/lib/shiny-server

# Create the log folder for shiny-server  (if req.) and set permissions
RUN sudo mkdir -p /var/log/shiny-server/
RUN sudo chown shiny /var/log/shiny-server/
RUN sudo chgrp shiny /var/log/shiny-server/
RUN sudo chmod g=rwx /var/log/shiny-server/ -R

COPY shiny-server.conf /etc/shiny-server/shiny-server.conf
COPY shiny-server.sh /usr/bin/shiny-server.sh

USER shiny
ENTRYPOINT ["sh","/usr/bin/shiny-server.sh"]

--->The entrypoint runs the renv restore and starts the shiny-server

Docker Compose:

version: "3.7"

services:
    shiny:
        image: shiny:latest
        #container_name: shiny
        deploy:
            replicas: 1
            restart_policy:
                condition: on-failure
        user: 'shiny'
        ports:
          - "3838:3838"
          - "8787:8787"
        volumes:
          - 'shinyServer_logs:/var/log/shiny-server/'
          - './shiny/app:/srv/shiny-server/app'
        networks:
            - overlay-network
        environment:
            - SHINY_PORT=3838
            - SHINY_MODE=shiny

volumes:
    shinyServer_logs:
    shinyApp_logs:

networks:
    overlay-network:
        driver: overlay

My shiny-server conf:

# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;

# Define a server that listens on port 3838
server {
  listen 3838;

  # Define a location at the base URL
  location / {
    app_idle_timeout 0;
    app_dir /srv/shiny-server/app;
    ## Host the directory of Shiny Apps stored in this directory
    #site_dir /srv/shiny-server;

    # Log all Shiny output to files in this directory
    log_dir /var/log/shiny-server;

    ## When a user visits the base URL rather than a particular application,
    ## an index of the applications available in this directory will be shown.
    # directory_index on;
  }
}
Seyphaton commented 3 years ago

I realised that your are resetting the env variable here: https://github.com/rstudio/shiny-server/blob/da6c4852c4c99189e75f5bc740eac1b199626d70/R/SockJSAdapter.R#L23

Where is this input coming from?

jcheng5 commented 3 years ago

If you're deriving from rocker/shiny, I don't think you need to do any of that stuff in your Dockerfile, other than COPY shiny-server.conf /etc/shiny-server/shiny-server.conf

I have no idea how port is getting unset though--it's being set just a couple of lines above that runApp call.