Error when flexdashboard.Rmd is deployed via shiny proxy

Hi all,

I have build a Dockerimage with CMD [“R”, “-e”, “rmarkdown::run(file=‘bin/Dashboard_kursnet_ranking.Rmd’, shiny_args = list(port = 3838, host = ‘0.0.0.0’))”]

as last line and as well as put this command in the application.yml. The proxy image runs and I can see the name of my App, however it does not work. I get Error:image

This is my flexdashboard dockerfile:

FROM rocker/shiny-verse:latest 

MAINTAINER Tim M.Schendzielorz "tim.schendzielorz@googlemail.com"
 
# Install dependencies 

RUN  echo 'install.packages(c("dplyr","dbplyr","DBI","DT","plotly","flexdashboard","lubridate"), \
        repos="http://cran.us.r-project.org", \
        dependencies=TRUE)' > /tmp/packages.R \
        && Rscript /tmp/packages.R
	
	

COPY Dashboard_kursnet_ranking.Rmd       /bin/Dashboard_kursnet_ranking.Rmd   

# make all app files readable (solves issue when dev in Windows, but building in Ubuntu)
RUN chmod -R 755 /bin

EXPOSE 3838

CMD ["R", "-e", "rmarkdown::run(file='bin/Dashboard_kursnet_ranking.Rmd', shiny_args = list(port = 3838, host = '0.0.0.0'))"]

This is my application.yml file:

  title: proxy_dashboards
  hide-navbar: false
  landing-page: /
  
  port: 3838
  docker:
    internal-networking: true
  specs:
  - id: 01_kursnet_dashboard
    display-name: Kursnet Dashboard
    description: 
    container-cmd: ["R", "-e", "rmarkdown::run(file='root/Dashboard_kursnet_ranking.Rmd', shiny_args = list(port = 3838, host = '0.0.0.0'))"]
    container-image: kursnetdashboard
    container-network: kt-net
    container-env:
      user: "shiny"
      environment:
        - APPLICATION_LOGS_TO_STDOUT=false 

logging:
  file:
   shinyproxy.log

EDIT: I start the shiny proxy docker container with:
docker run -d -v /var/run/docker.sock:/var/run/docker.sock --net kt-net -p 3838:3838 shiny_proxy
I included the test shiny app from shiny proxy in the application.yml. This test app works fine when I access it via localhost:3838:

 - id: 02_test
    display-name: test
    description: Application which demonstrates the basics of a Shiny app
    container-cmd: ["R", "-e", "shinyproxy::run_06_tabsets()"]
    container-image: openanalytics/shinyproxy-demo
    container-network:  kt-net

Could it be just the typo in the command?

where you have root/ instead of /bin/ as in the Dockerfile you pasted? (note that first slash is also needed, i.e. just bin/ wouldn’t work)

Hi,
I changed CMD in the Dockerfile and container-cmd: in the application.yml to

[“R”, “-e”, “rmarkdown::run(file=‘/bin/Dashboard_kursnet_ranking.Rmd’, shiny_args = list(port = 3838, host = ‘0.0.0.0’))”]

now I get this Error:
image

Does the app work if launched from docker outside shinyproxy as described in https://www.shinyproxy.io/troubleshooting/
Can you check the shinyptoxy log file to see if there are any pointers to the actual error?

Hi,

the problem is not with the dockerized shiny_proxy but with the dockerized flexdashboard connecting to a SQL database at another port.
If I run it outside shiny proxy I get following Error :

Error in .local: Failed to connect to database: Error: Can't connect to MySQL server on '0.0.0.0' (107)

I have a google cloud proxy connection at port 3306, however the shiny app inside the docker seems not to be able to connect to it. I also made a docker-compose.yml and ran a google cloud proxy in a docker container within a shared network. Same error.
Here is my docker-compose.yml. The shiny-proxy test app as seen in the edit of my original post works still fine. The problem seems the communication between the cloud proxy docker image at port 3306 and the shiny_proxy at port 3838. I already changed the IP inside the DBI connection in the shiny app to “localhost”. Any suggestions? Thank you for your help so far @mnazarov!

version: "3.6"
services:
  shinyproxy:
    depends_on:
     
      - cloudsql-proxy
     

    image: shiny_proxy
    container_name: tmpe
    networks:
      - kt-net
    volumes:
      - ./application.yml:/opt/shinyproxy/application.yml
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "3838:3838"

    restart: always

  cloudsql-proxy:
      container_name: cloudsql-proxy
      image: gcr.io/cloudsql-docker/gce-proxy:1.11
      command: /cloud_sql_proxy --dir=/cloudsql -instances=servername:europe-west3:name=tcp:0.0.0.0:3306 -credential_file=/secrets/cloudsql/secrets.json
      ports:
        - "3306:3306"
      networks:
        - kt-net
      volumes:
        - ./secrets.json:/secrets/cloudsql/secrets.json
      restart: always

networks:
     kt-net:
      name: kt-net

Hi,
I also ran the app outside of shiny_proxy. And I get an Error with the Syntax here:
image

you need to put quotes around the command since it contains spaces

... R -e "rmarkdown::run(file='/bin/Dashboard_kursnet_ranking.Rmd', shiny_args = list(port = 3838, host = '0.0.0.0'))"

Regarding your other question, it seems to be not a shinyproxy issue per se, but a matter of correct configuration via docker compose, and unfortunately I can’t help much here.

1 Like

Hi,

this was a wild ride and I want to share how I solved the deployment issues:

  1. building a dockerized flexdashboard:
    The original image with the rocker/shiny-verse image as base was not working, I build the Image from this Dockerfile instead:
    https://github.com/timosch29/Dockerized-Shiny-Proxy/blob/master/example_dashboard/Dockerfile

  2. running the dockerized shiny-proxy:
    adding the slash and and quotations in the container-cmd as suggested.

  3. running the shiny proxy container together with a my sql-proxy via docker-compose:
    adding a my-sql client lib to the flexdashboard dockerfile as well as changing the localhost of the DBI connection to the container name of the sql-proxy container. Manage DBI connection via the R pool package.

Hi,
I am glad you made it work, and thanks for sharing.
Just FYI, I see some extraneous steps in your Dockerfile:

  • you don’t need to install shiny-server, since it is not needed for shiny proxy, and moreover you seem to never use it
  • you don’t need the whole devtools package, installing remotes would be sufficient (and faster to install), or maybe it is not even needed, since you are installing only from CRAN.

Overall it seems that you just lacked the RMySQL package and its system dependencies (libmariadb) in your original Dockerfile.

2 Likes

Hi Tim.

Could you please share the exact command for mysql you used in the Docker-file (or all part of your Dockerfile which are not private)? Also more info about your mysql setup in flexdashboard & your docker compose would be immensely helpful to me. I am struggling with the same problem for more than a week & getting desperate. Thank you!

Hello kutyakot,

I might be able to help. Can you please open a new topic here with your relevant code and issues and link it here in a reply? I think otherwise it will get too much just for a single topic.

Hi Tim. Thanks for the reply. Sure, I made a new topic topic .