Docker Community Forums

Share and learn in the Docker community.

R Shiny DataTables giving Ajax error using Docker swarm

I’ve set up a Docker swarm on a single machine with 5 replicas containing an R Shiny application (docker-compose.yml copied below).

On visiting the site and attempting to display a datatable, I get the following error:

DataTables warning: table id=DataTables_Table_1 - Ajax error. For more information about this error, please see http://datatables.net/tn/7

This only occurs when using Docker swarm. When I manually run the shiny app from within a running Docker container (created from the same image as used for the Docker swarm) the datatable displays as expected without error.

I’ve reinstalled htmlwidgets, DT and jsonlite packages from source using the devtools package.

Apart from the issue with the datatable the app runs fine. Example of code for outputting table from Shiny app.R:

output$di_infra = DT::renderDataTable({
dt_table(di_dt)
})

I guess the problem may relate to the configuration of my docker-compose.yml file or a bug?

My docker-compose.yml file:

version: "3.7"
services:
   dataservice:
   image: docker_image_name
   deploy:
      replicas: 5
      restart_policy:
        condition: on-failure
ports:
  - "9193:3838"
volumes:
  - '/home/user/webapps/project_name:/home/user/webapps/project_name'
  - '/home/tomcat:/home/tomcat'
  - '/gisdata:/gisdata'

I also noticed that some css rules are not being applied (though minor) when using the Docker swarm. This may or may not be another issue.

Many thanks for any suggestions.

docker --version
Docker version 18.09.6, build 481bc77
Host and Docker OS: Ubuntu 18.04
R version 3.6.2

If I add server = FALSE to the renderDataTable function the tables are displayed, but are slow to display initially.

I’ve also posted this issue to https://github.com/rstudio/DT/issues/849 as not sure if this is more a DT-related issue.

Since you claim you deploy the shiny app on DigitalOcean and the app works well locally, I suspect the DT version on your server is not the latest.

You can check the version of DT by adding something like outputText(“dt_version”) to ui.R and output$dt_version <- renderText(packageVersion(“DT”)) to server.R.

If not, please install the developing version of DT via devtools::install_github(‘rstudio/DT’) and try again (I bet you are using shiny-server, please remember to restart the server to ensure the newly installed package being loaded).

I updated DT again from github to the latest version but the error still remains.

remotes::install_github(‘rstudio/DT’)
packageVersion(“DT”)
[1] ‘0.15.5’

The app is installed on my own server. I only experience the problem with Docker swarm which launches the app from a Docker image (see docker-compose.yml). If I run the Shiny app within a docker container which also has a Shiny server installation, the DT table works as expected. I use Packrat to manage all packages for a given app and these are installed as a volume on the host machine.

I am also getting an error when using the Downloadhandler function in Shiny: it does not download the file when using Docker swarm, but works fine if running the Shiny app within a Docker container.

On reading around further on this issue it appears that it might be related to sticky sessions… I have a single node, which with 5 replicas gives an error with DT and DownloadHandler, but there are no errors with one replica. I guess Traefik might be a solution?

I tried to resolve the issue with Traefic (see https://github.com/rstudio/DT/issues/849), but the problem still persists: swarm mode appears to be enabled in Traefic, but the DT package and downloadHandler are still problematic. It appears that these functionalities work with one of the swarm replica containers but the other container replicas show 404 codes for related css/js files (unless my configuration for Traefic is incorrect).