Commit cec6c892 authored by jbleher's avatar jbleher
Browse files

ome changes to the Dockerfile the script , the template and the

docker-compose file
parent d30a512c
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
# Base R image
FROM rocker/r-ver:latest
FROM rocker/verse:latest

RUN apt update && apt install -y cron \
RUN apt update && apt install -y cron vim \
    && apt-get clean

# Make a directory in the container
RUN mkdir /home/r-environment

# Install R dependencies
RUN R -e "install.packages(c('dplyr','httr', 'leaflet', 'htmlwidgets', 'lubridate','jsonlite'))"
RUN R -e "install.packages(c('dplyr','httr', 'leaflet', 'htmlwidgets', 'lubridate','jsonlite','htmlTable', 'rmarkdown', 'flexdashboard','kableExtra','knitr'))"

# Create a stub for our R script to the container
# Create a stub for our R script and Rmd file to the container
RUN touch /home/r-environment/script.R
RUN touch /home/r-environment/template.Rmd

# Copy the script.sh file to the container
COPY script.sh /home/r-environment/script.sh

# Make the script executable
+22 −2
Original line number Diff line number Diff line
#!/bin/bash

# Define paths
SCRIPT_DIR="/home/r-environment"
LOG_DIR="${SCRIPT_DIR}/logs"
DATA_DIR="${SCRIPT_DIR}/downloads"
DASH_DIR="${SCRIPT_DIR}/dashboard"

# Create necessary directories if they don't exist
mkdir -p $LOG_DIR
mkdir -p $DATA_DIR
mkdir -p $DASH_DIR

# Export PATH
export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/sbin:/bin:/usr/sbin
cd /home/r-environment/
/usr/local/bin/Rscript /home/r-environment/script.R >> /home/r-environment/logs/cron.log 2>&1

# Change to the script directory
cd $SCRIPT_DIR

# Run the R script to download data
/usr/local/bin/Rscript $SCRIPT_DIR/script.R >> $SCRIPT_DIR/logs/cron.log 2>&1

# Render the R Markdown file
/usr/local/bin/Rscript -e "rmarkdown::render('${SCRIPT_DIR}/template.Rmd', output_file='${DASH_DIR}/dashboard.html')" >> ${LOG_DIR}/cron_rmarkdown.log 2>&1
+43 −0
Original line number Diff line number Diff line
---
title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}

#TODO: Adjust correctly for the docker container
subfolder = "01_data/raw"

library("flexdashboard")
library("leaflet")
library("htmlwidgets")
library("lubridate")
library("jsonlite")
library("dplyr")
library("knitr")
library("kableExtra")

```

Column {data-width=500}
-----------------------------------------------------------------------

### Chart A

```{r}
# Here goes the code for the leaflet
```


Column {data-width=500}
-----------------------------------------------------------------------

### Table A

```{r}
# Here goes the code for the table
```
+17 −3
Original line number Diff line number Diff line
@@ -4,16 +4,30 @@ services:
      context: ./02_code/docker
      dockerfile: Dockerfile
    volumes:
      # This is the R script file
      # This is the R Download script file
      # TODO: change the placeholder <NAME OF YOUR SCRIPT>
      - "./02_code/R/<NAME OF YOUR SCRIPT>:/home/r-environment/script.R:rw"
      # This is the cron file
      # TODO: Change the content of the file to run every day
      - "./02_code/cron_file/my-crontab:/etc/cron.d/my-crontab:rw"
      # # This is the Rmd file that create the dashboard
      # # TODO TASK4: change the placeholder <NAME OF YOUR Rmd>
      # - "./04_dashboard/<NAME OF YOUR Rmd>:/home/r-environment/template.Rmd:rw"
      # This is the shell script that starts the R script
      - "./02_code/docker/script.sh:/home/r-environment/script.sh:rw"
      # This is the download folder where all the downloaded data go
      - "./01_data/downloads/:/home/r-environment/downloads/:rw"
      # # This is the dashboard folder
      # # TODO TASK4
      # - "./01_data/dashboard/:/home/r-environment/dashboard/:rw"
      # This is the logs folder
      - "./01_data/logs/:/home/r-environment/logs/:rw"
    
  #  TODO TASK4   
  # nginx:
  #   image: nginx:latest
  #   ports:
  #     - "80:80"
  #   volumes:
  #     - "./01_data/dashboard/:/usr/share/nginx/html/:rw"
  #   depends_on:
  #     - rscript
 No newline at end of file