Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
webmice.Rproj
swagger-ui.html
14 changes: 7 additions & 7 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM rocker/r-ver:4.3.1
LABEL version="0.1"
LABEL version="0.1.1"
LABEL description="Docker container running webmice (R, RestRserve)"

ARG R_VERSION=4.3.1
Expand All @@ -16,19 +16,19 @@ RUN apt update && \

#RUN echo 'options(repos = c(CRAN = "https://cloud.r-project.org"))' >>"${R_HOME}/etc/Rprofile.site"
RUN R -e "install.packages('RestRserve', repos = 'https://cloud.r-project.org')"
RUN R -e "install.packages('jsonlite')"
RUN R -e "install.packages('remotes')"
RUN R -e "remotes::install_github('amices/mice')"
RUN R -e "remotes::install_github('amices/micerocker')" # 0.1.3

# Pull in webmice code
RUN mkdir /home/webmice
RUN rm -rf /home/webmice
# Create working directory
RUN mkdir /home/webmice
ENV WEBMICE_LOC="/home/webmice"

# Create data directory
RUN mkdir /home/webmice/data_uploads
ENV MICEROCKER_DATA_UPLOADS="/home/webmice/data_uploads"

COPY webmice.R /home/webmice/webmice.R
COPY webmice_handlers.R /home/webmice/webmice_handlers.R
COPY webmice_functions.R /home/webmice/webmice_functions.R
COPY ../openapi.yaml /home/webmice/openapi.yaml

WORKDIR /home/webmice
Expand Down
28 changes: 11 additions & 17 deletions webmice.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
library(RestRserve)
library(mice, warn.conflicts = FALSE)
library(jsonlite)
library(readr)
library(digest)
# remotes::install_github("amices/micerocker")

require(mice, warn.conflicts = FALSE) # >= 3.16.4
require(micerocker) # >= 0.1.3
require(RestRserve)
require(readr)

#' Parameters
#' Code location in Docker, set through bash variable
base_folder <- Sys.getenv("WEBMICE_LOC")
if(base_folder == "") {
if (base_folder == "") {
base_folder <- getwd()
print('No base folder for webmice set (export WEBMICE_LOC="directory").')
print(paste("Set to: ", base_folder))
}

#' Imports
source(file.path(base_folder, "webmice_handlers.R"))
source(file.path(base_folder, "webmice_functions.R"))

#' Data upload location
data_uploads = file.path(base_folder, "data_uploads")
if(!file.exists(data_uploads)){
dir.create(data_uploads)
}
data_uploads <- "data_uploads"
Sys.setenv(MICEROCKER_DATA_UPLOADS = data_uploads)

#' Application
webmice = Application$new()
webmice = RestRserve::Application$new()

#' Endpoints
webmice$add_post(
Expand All @@ -48,7 +42,7 @@ webmice$add_get(path = "/long", FUN = impute_longfmt_handler)
webmice$add_get(path = "/fit", FUN = fit_handler)
webmice$add_get(path = "/pool", FUN = pool_handler)

#' Swagger
#' Swagger
yaml_file = file.path(base_folder, "openapi.yaml")
webmice$add_openapi(path = "/openapi.yaml", file_path = yaml_file)
webmice$add_swagger_ui(path = "/doc", path_openapi = "/openapi.yaml", use_cdn = TRUE)
Expand Down
134 changes: 0 additions & 134 deletions webmice_functions.R

This file was deleted.

69 changes: 0 additions & 69 deletions webmice_handlers.R

This file was deleted.