Facetgrid plot (with ggplotly) greyed out in docker container

  docker, ggplot2, plotly, r, r-markdown

For a daily report Rmarkdown script that I would like to encapsulate in a docker container I face a problem with a plotly plot that is created from ggplot facet_grid and then transformed using ggplotly.

When I run the script locally on R studio my plot is working as intended:
plotly_locally

When I run the script through my docker container, it is completely greyed out:

plotly_docker

The data is actually there, it is just not showing:

enter image description here

There is no differences between the scripts except for where I run it and I actually do not know where to look for solving that bug.

Here is the ggplot+plotly part inside the rmarkdown chunk:

p <- ggplot(table_plot_month, aes(x = action_date, y = n, fill = action_type)) +
      geom_bar(stat='identity') +
      facet_grid(orga_initiales ~ .) + theme_bw() +
      theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1), legend.position = "none") +
      labs(y = "Nombre Actions", x = "Date", fill = "Type action")

gp <- ggplotly(p)

gp <- ggplotly(p) 
gp[['x']][['layout']][['annotations']][[1]][['y']] <- -0.25
gp[['x']][['layout']][['annotations']][[2]][['x']] <- -0.07

gp %>% layout(margin = list(l = 120, b=70))

Here are the docker commands I’m using to create the image and running the container and binding the container output directory with the host output directory:

docker build -t daily_report_image C:/my_path

docker run -d --name daily_report -v ~/my_path:/home/output daily_report_image 

Here is the Dockerfile I am using to create my image:

FROM rocker/r-base

RUN apt-get update 
 && apt-get install --yes --no-install-recommends 
        apt-transport-https 
        curl 
        gnupg 
        unixodbc-dev 
        libfontconfig1-dev 
 && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 
 && curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list 
 && apt-get update 
 && ACCEPT_EULA=Y apt-get install --yes --no-install-recommends msodbcsql17 
 && install2.r odbc 
 && apt-get clean 
 && rm -rf /var/lib/apt/lists/* 
 && rm -rf /tmp/*

 RUN apt-get update 
    && apt-get install -y --no-install-recommends 
                ghostscript 
                lmodern 
                pandoc-citeproc 
                qpdf 
                r-cran-formatr 
                r-cran-ggplot2 
                r-cran-knitr 
                r-cran-rmarkdown 
                r-cran-runit 
                r-cran-testthat 
                r-cran-tidyverse 
                r-cran-stringr 
                r-cran-lubridate 
                r-cran-plotly 
                r-cran-formattable 
                r-cran-here 
        && install.r binb linl pinp tint 
        && mkdir ~/.R 
        && echo _R_CHECK_FORCE_SUGGESTS_=FALSE > ~/.R/check.Renviron 
        && cd /usr/local/bin 
        && ln -s /usr/lib/R/site-library/littler/examples/render.r .

RUN R -e "install.packages('fontawesome')"
RUN R -e "install.packages('kableExtra')"
RUN R -e "install.packages('flexdashboard')"

WORKDIR /home

COPY src/suivi_activite_html.Rmd suivi_activite_html.Rmd
COPY src/run_all_daily_reports.R run_all_daily_reports.R
COPY .env .env

CMD R -e "source('run_all_daily_reports.R')"

Any idea where I should look? Is it a docker problem, a plotly/ggplot compatibility problem?

Source: Docker Questions

LEAVE A COMMENT