-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from FredHutch/dev
shiny-cromwell v1.1.0 Updates
- Loading branch information
Showing
13 changed files
with
370 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
FROM fredhutch/r-shiny-server-base:4.3.2 | ||
|
||
RUN apt-get update -y && apt-get install -y libssh-dev | ||
RUN apt-get update -y && apt-get install -y libssh-dev python3-pip git libmariadb-dev | ||
|
||
RUN R -q -e 'install.packages(c("ellipsis"), repos="https://cran.rstudio.com/")' | ||
RUN R -q -e 'install.packages(c("shiny"), repos="https://cran.rstudio.com/")' | ||
RUN R -q -e 'install.packages(c("shinyFeedback", "shinyWidgets", "shinydashboard", "shinydashboardPlus", "ssh", "remotes", "markdown", "lubridate", "jsonlite", "dplyr", "DT", "glue", "httr", "purrr", "RColorBrewer", "rlang", "shinyBS", "shinyjs", "tidyverse", "uuid", "memoise", "rclipboard", "shinyvalidate", "shinylogs", "testhat"), repos="https://cran.r-project.org")' | ||
RUN R -q -e 'install.packages(c("shinyFeedback", "shinyWidgets", "shinydashboard", "shinydashboardPlus", "ssh", "remotes", "markdown", "lubridate", "jsonlite", "dplyr", "DT", "glue", "httr", "purrr", "RColorBrewer", "rlang", "shinyBS", "shinyjs", "tidyverse", "uuid", "memoise", "rclipboard", "shinyvalidate", "shinylogs", "testhat", "bsicons", "listviewer", "cookies", "RMariaDB", "DBI"), repos="https://cran.r-project.org")' | ||
|
||
RUN R -q -e "remotes::install_github('getwilds/proofr@v0.2')" | ||
RUN R -q -e "remotes::install_github('getwilds/proofr@v0.3.0')" | ||
|
||
RUN R -q -e "remotes::install_github('getwilds/[email protected]')" | ||
RUN R -q -e "remotes::install_github('getwilds/[email protected]')" | ||
|
||
ADD .my.cnf /root/ | ||
|
||
# python wdl2mermaid setup: | ||
RUN pip install git+https://github.com/chanzuckerberg/miniwdl-viz.git | ||
|
||
RUN R -q -e "remotes::install_github('timelyportfolio/reactR')" | ||
|
||
RUN rm -rf /srv/shiny-server/ | ||
COPY app/ /srv/shiny-server/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
library(RMariaDB) | ||
library(DBI) | ||
|
||
COOKIE_EXPIRY_DAYS <- 14 | ||
|
||
to_base64 <- function(x) { | ||
base64enc::base64encode(charToRaw(x)) | ||
} | ||
from_base64 <- function(x) { | ||
rawToChar(base64enc::base64decode(x)) | ||
} | ||
|
||
db <- dbConnect(RMariaDB::MariaDB(), group = "shinycromwell") | ||
if (!dbExistsTable(db, "users")) { | ||
db_columns <- c( | ||
user = "TEXT", | ||
proof_token = "TEXT", | ||
cromwell_url = "TEXT", | ||
login_time = "TEXT" | ||
) | ||
dbCreateTable(db, "users", db_columns) | ||
} | ||
dbDisconnect(db) | ||
|
||
make_db_con <- function() { | ||
dbConnect(RMariaDB::MariaDB(), group = "shinycromwell") | ||
} | ||
|
||
user_from_db <- function(user, conn = make_db_con(), expiry = COOKIE_EXPIRY_DAYS) { | ||
on.exit(dbDisconnect(conn)) | ||
dbReadTable(conn, "users") %>% | ||
as_tibble() %>% | ||
filter( | ||
# !! needed to get the value of the variable | ||
user == !!user, | ||
login_time > now() - days(expiry) | ||
) %>% | ||
arrange(desc(login_time)) | ||
} | ||
user_to_db <- function(user, token, url, drop_existing = FALSE, conn = make_db_con()) { | ||
on.exit(dbDisconnect(conn)) | ||
# drop before inserting so we only have 1 row/user | ||
if (drop_existing) { | ||
# don't drop if user is empty | ||
if (nzchar(user)) { | ||
# don't disconnect from within drop fun | ||
user_drop_from_db(user, disconnect = FALSE, conn = conn) | ||
} | ||
} | ||
tibble( | ||
user = user, | ||
proof_token = token, | ||
cromwell_url = url, | ||
login_time = as.character(now()) | ||
) %>% | ||
dbWriteTable(conn, "users", ., append = TRUE) | ||
} | ||
user_drop_from_db <- function(user, disconnect = TRUE, conn = make_db_con()) { | ||
if (disconnect) { | ||
on.exit(dbDisconnect(conn)) | ||
} | ||
sql_delete <- glue::glue_sql(" | ||
DELETE from users | ||
WHERE user = {user} | ||
", .con = conn) | ||
dbExecute(conn, sql_delete) | ||
} |
Oops, something went wrong.