-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initialize second app within package
keeping it as a completely separate app with its own app directory copied www folder as-is de-activated login, hard-coded <test_user> for now
- Loading branch information
Showing
22 changed files
with
8,181 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
############################################################################### | ||
# note with shiny::runApp this statement isn't needed anymore | ||
# library(shiny, warn.conflicts = FALSE, quietly = TRUE) | ||
|
||
library(oasisui, warn.conflicts = FALSE) | ||
|
||
#Extend max uploadable file size from default 400MB, with option to read size in MB from env | ||
env_upload = as.integer(Sys.getenv("MAX_UPLOAD_SIZE", unset = 400)) | ||
if (is.na(env_upload) || env_upload < 400) {upload_size = 400} else {upload_size = env_upload} | ||
options(shiny.maxRequestSize = upload_size*1024^2) | ||
|
||
### logger --------------------------------------------------------------------- | ||
loginfo("testing logger", logger = "oasisui.module") | ||
|
||
### Django API ----------------------------------------------------------------- | ||
|
||
APISettings <- APIgetenv(server = "API_IP", | ||
port = "API_PORT", | ||
scheme = "API_HTTPS", | ||
version = "API_VERSION", | ||
share_filepath = "API_SHARE_FILEPATH") | ||
|
||
options(oasisui.settings.api.server = APISettings$server) | ||
options(oasisui.settings.api.port = APISettings$port) | ||
if (isTRUE(as.logical(APISettings$scheme))) { | ||
options(oasisui.settings.api.scheme = "https") | ||
} else { | ||
options(oasisui.settings.api.scheme = "http") | ||
} | ||
options(oasisui.settings.api.httptype = "application/json") | ||
options(oasisui.settings.api.version = APISettings$version) | ||
options(oasisui.settings.api.share_filepath = APISettings$share_filepath) | ||
|
||
options(oasisui.settings.admin.mode = Sys.getenv("ADMIN_MODE")) | ||
options(oasisui.settings.hide_footer = Sys.getenv("HIDE_FOOTER_VERSION", unset = FALSE)) | ||
|
||
options(oasisui.settings.oasis_environment = Sys.getenv("OASIS_ENVIRONMENT")) |
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,240 @@ | ||
############################################################################### | ||
|
||
# UI content that is rendered once the user has authenticated | ||
source(file.path(".", "ui_auth.R"), local = TRUE)$value | ||
#clean up API_SHARE_FILEPATH folder upon app launch | ||
clean_downloadedData() | ||
|
||
#' server | ||
#' | ||
#' @rdname server | ||
#' | ||
#' @template params-module | ||
#' | ||
#' @return Server. | ||
#' @export | ||
|
||
server <- function(input, output, session) { | ||
|
||
# initialize oasisapi R6 classes for managing connection to API in OasisUI | ||
session$userData$oasisapi <- OasisAPI$new( | ||
host = getOption("oasisui.settings.api.server"), | ||
port = getOption("oasisui.settings.api.port"), | ||
scheme = getOption("oasisui.settings.api.scheme"), | ||
version = getOption("oasisui.settings.api.version") | ||
) | ||
|
||
print(getOption("oasisui.settings.api.scheme")) | ||
# per-session health check | ||
loginfo(paste("oasisui API server:", session$userData$oasisapi$get_url()), logger = "oasisui.module") | ||
# tryCatch({ | ||
# invisible(session$userData$oasisapi$api_get_healthcheck()) | ||
# }, error = function(e) { | ||
# showModal( | ||
# modalDialog( | ||
# "API is down. Please try again later", | ||
# footer = NULL, | ||
# size = "m", | ||
# fade = FALSE | ||
# ) | ||
# ) | ||
# logerror(e$message, logger = "oasisui.module") | ||
# }) | ||
session$userData$oasisapi$set_tokens("test_user", "mirai123") | ||
|
||
session$userData$data_hub <- DataHub$new( | ||
user = session$userData$oasisapi$get_access_token(), | ||
destdir = getOption("oasisui.settings.api.share_filepath"), | ||
oasisapi = session$userData$oasisapi | ||
) | ||
|
||
# active main panel based on the reactive navigation state | ||
navigation_state <- reactiveNavigation("LP") | ||
main_visible <- getNavigation(outputNavigation( | ||
# force_react = FALSE allows reacting only to actual changes | ||
navigation_state, force_react = FALSE | ||
)) | ||
|
||
result <- reactiveValues( | ||
user = "guest", | ||
WidthMain = 9, | ||
WidthSide = 3, | ||
preselPanel = 1 | ||
) | ||
|
||
authenticated <- reactive({ | ||
# reactive expression yielding TRUE when: | ||
# - user has been matched to an id | ||
# - ui has been rendered (input values are available) | ||
auth <- (result$user != OASISUI_GUEST_ID) && | ||
!is.null(input$authUIRenderCallback) | ||
|
||
if (auth) logMessage("Authenticated") | ||
|
||
return(auth) | ||
}) %>% debounce(100) | ||
|
||
# submodules ---- | ||
|
||
loginDialogModule <- callModule( | ||
loginDialog, "login", | ||
logout = reactive(auth_modules$pageheader$logout()) | ||
) | ||
|
||
# observe({ | ||
# result$user <- loginDialogModule$user() | ||
# }) | ||
|
||
# list of modules for the authenticated UI | ||
auth_modules <- list() | ||
|
||
auth_modules$pageheader <- callModule( | ||
pageheader, "pageheader", | ||
user = reactive(result$user), | ||
active = reactive(authenticated()) | ||
) | ||
|
||
auth_modules$pagestructure <- callModule( | ||
pagestructure, "pagestructure", | ||
active = reactive(authenticated()) | ||
) | ||
|
||
auth_modules$landingPage <- callModule( | ||
landingPage, "landingPage", | ||
active = reactive(authenticated() && main_visible() == "LP") | ||
) | ||
|
||
auth_modules$singleAna <- callModule( | ||
singleAna, | ||
id = "singleAna", | ||
preselPanel = reactive(result$preselPanel), | ||
selectAnaID = auth_modules$visualizationSBR$selectAnaID, | ||
selectPortfolioID = auth_modules$visualizationSBR$selectPortfolioID, | ||
active = reactive(authenticated() && main_visible() == "SA") | ||
) | ||
|
||
# auth_modules$batchAna <- callModule( | ||
# batchAna, | ||
# id = "batchAna", | ||
# active = reactive(authenticated() && main_visible() == "BA") | ||
# ) | ||
|
||
auth_modules$visualizationSBR <- callModule( | ||
visualizationSBR, | ||
id = "visualizationSBR", | ||
preselAnaId = auth_modules$landingPage$anaID, | ||
anaID = auth_modules$singleAna$anaID, | ||
active = reactive(authenticated() && main_visible() == "SBR") | ||
) | ||
|
||
# auth_modules$visualizationBBR <- callModule( | ||
# visualizationBBR, | ||
# id = "visualizationBBR", | ||
# preselAnaId = reactive(NULL), | ||
# anaID = reactive(NULL), | ||
# active = reactive(authenticated() && main_visible() == "BBR") | ||
# ) | ||
|
||
# auth_modules$visualizationCBR <- callModule( | ||
# visualizationCBR, | ||
# id = "visualizationCBR", | ||
# preselAnaId = reactive(NULL), | ||
# anaID = reactive(NULL), | ||
# active = reactive(authenticated() && main_visible() == "CBR") | ||
# ) | ||
|
||
# authenticated ---- | ||
# show the logged-in part of the UI if login is completed | ||
appState <- reactive( | ||
# cannot use authenticated() here and below in renderUI(... authUI(...))! | ||
#if (authenticated()) "loggedin" else "loggedout" | ||
if (result$user != OASISUI_GUEST_ID) "loggedin" else "loggedout" | ||
) | ||
|
||
callModule(reactiveConditionalPanels, "appUI", appState) | ||
|
||
### Module input parameters depending on othe rmodules outputs --- | ||
|
||
# UI non-reactive to (result$WidthSide) and (result$Widthmain) | ||
output$authUI <- renderUI( | ||
#if (authenticated()) { | ||
if (result$user != OASISUI_GUEST_ID) { | ||
authUI( | ||
WidthSide = isolate(result$WidthSide), | ||
WidthMain = isolate(result$WidthMain) | ||
) | ||
} | ||
) | ||
# reactivity via dynamicColumn module | ||
callModule(dynamicColumn, "sidebar", reactive(result$WidthSide)) | ||
callModule(dynamicColumn, "main", reactive(result$WidthMain)) | ||
|
||
observe(result$logout <- auth_modules$pageheader$logout()) | ||
|
||
# preselected panel | ||
observe({ | ||
if (!is.null(auth_modules$visualizationSBR$preselPanel)) { | ||
result$preselPanel <- auth_modules$visualizationSBR$preselPanel() | ||
} else { | ||
result$preselPanel <- 1 | ||
} | ||
}) | ||
|
||
# collapse / expand sidebar ---- | ||
observe({ | ||
if (auth_modules$pagestructure$collapsed()) { | ||
result$WidthMain <- 11 | ||
result$WidthSide <- 1 | ||
} else { | ||
result$WidthMain <- 9 | ||
result$WidthSide <- 3 | ||
} | ||
}) | ||
|
||
### navigation ---- | ||
# observe the possible navigation state propagated from any module | ||
observeModuleNavigation(navigation_state, auth_modules, logger = NULL) | ||
|
||
# activate the main panel the user navigates to | ||
callModule(reactiveConditionalPanels, "mainPanel", main_visible) | ||
|
||
|
||
# TODO: Consider simplifying the logging of the navigation using the `logger` | ||
# argument of `observeModuleNavigation()` above. | ||
observe(if (authenticated()) { | ||
switch(main_visible(), | ||
|
||
"SA" = { # go to Define programme single submenu | ||
loginfo(paste("Navigate to Define Single Analysis"), | ||
logger = "oasisui.module") | ||
}, | ||
|
||
# "BA" = { # go to Define programme batch submenu | ||
# loginfo(paste("Navigate to Define Batch Analysis"), | ||
# logger = "oasisui.module") | ||
# }, | ||
|
||
"SBR" = { # go to Single browse submenu | ||
loginfo(paste("Navigate to Single browse"), | ||
logger = "oasisui.module") | ||
}, | ||
|
||
# "BBR" = { # go to Batch browse submenu | ||
# loginfo(paste("Navigate to Batch browse"), | ||
# logger = "oasisui.module") | ||
# }, | ||
# | ||
# "CBR" = { # go to Compare Runs submenu | ||
# loginfo(paste("Navigate to compare runs"), | ||
# logger = "oasisui.module") | ||
# }, | ||
|
||
"LP" = { # go to Landing Page | ||
loginfo(paste("Navigate to Landing Page"), | ||
logger = "oasisui.module") | ||
}, | ||
|
||
stop("page does not exist") | ||
) | ||
}) | ||
} |
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,39 @@ | ||
############################################################################### | ||
|
||
#' ui | ||
#' | ||
#' @rdname ui | ||
#' | ||
#' @param request ui before authentification. | ||
#' | ||
#' @return ui before authentification. | ||
#' | ||
#' @export | ||
|
||
ui <- function(request) { | ||
|
||
fluidPage( | ||
tags$head( | ||
#tags$script('window.onbeforeunload = function(event) {return "";};'), | ||
tags$link(rel = "stylesheet", type = "text/css", href = "css/bootstrap.css"), | ||
tags$link(rel = "stylesheet", type = "text/css", href = "css/oasisui-tweaks.css"), | ||
tags$link(rel = "stylesheet", type = "text/css", href = "css/oasisui-table.css"), | ||
tags$link(rel = "icon", type = "image/x-icon", href = "img/favicon_oasis.png"), | ||
bsplus::use_bs_tooltip() | ||
), | ||
shinyjs::useShinyjs(), | ||
shinyjs::extendShinyjs(script = system.file("app", "www", "js", "oasisui.js", package = "oasisui")), | ||
|
||
title = "OasisUI", | ||
|
||
reactiveConditionalPanelsUI( | ||
"appUI", | ||
list( | ||
loggedout = loginDialogUI("login"), | ||
loggedin = uiOutput("authUI") | ||
) | ||
) | ||
|
||
) # End of fluidpage | ||
} | ||
|
Oops, something went wrong.