Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
jlopez
sagJL
Commits
3b69a05e
Commit
3b69a05e
authored
Nov 03, 2021
by
khalid
Browse files
Add authentification to app
parent
d570bb65
Changes
1
Hide whitespace changes
Inline
Side-by-side
main.R
View file @
3b69a05e
#!/usr/bin Rscript
# This script will take a SAG yaml configuration file and generate a ShinyApp
# Accepts
two
parameters: path to sag yaml configuration file
# Accepts
four
parameters: path to sag yaml configuration file
, output dir, user and passwd
# Usage: Rscript /path/to/sag.yaml /output/dir/
args
=
commandArgs
(
trailingOnly
=
TRUE
)
source
(
"tools.R"
)
...
...
@@ -8,6 +8,8 @@ library(yaml)
path_yml
<-
args
[
1
]
output_dir
<-
args
[
2
]
user
<-
args
[
3
]
passwd
<-
args
[
4
]
APP
<<-
yaml.load_file
(
path_yml
,
handlers
=
list
(
"float#fix"
=
function
(
x
){
format
(
x
,
scientific
=
F
)}))
$
App
...
...
@@ -834,7 +836,9 @@ generate_app <- function() {
res
<-
res
+
'library(DT)\n'
res
<-
res
+
'\n\n'
res
<-
res
+
'user_base <- tibble::tibble( user = "'
+
user
+
'", password = "'
+
passwd
+
'",\n\n'
res
<-
res
+
'permissions = "standard",name = "User One") \n\n'
res
<-
res
+
'source("./R/chooser.R", local=T)\n\n'
for
(
x
in
1
:
length
(
APP
$
pages
))
{
...
...
@@ -866,6 +870,7 @@ generate_app <- function() {
res
<-
res
+
' dashboardHeader(title="'
+
main
$
title
+
'", titleWidth='
+
main
$
menu_width
+
'),\n\n'
res
<-
res
+
' dashboardSidebar(width='
+
main
$
menu_width
+
', MenuGauche),\n\n'
res
<-
res
+
' dashboardBody(\n\n'
res
<-
res
+
' div(class = "pull-right", shinyauthr::logoutUI(id = "logout")), shinyauthr::loginUI(id = "login"),\n\n'
res
<-
res
+
' shinyjs::useShinyjs(),\n\n'
res
<-
res
+
' tags$head(tags$link(rel="stylesheet", type="text/css", href="bootstrap.min.readable.css")),\n\n'
...
...
@@ -949,6 +954,21 @@ generate_app <- function() {
res
<-
res
+
'\n\n'
res
<-
res
+
'server <- function( input, output, session) {\n\n'
res
<-
res
+
' credentials <- shinyauthr::loginServer( id = "login",data = user_base, user_col = user, pwd_col = password, log_out = reactive(logout_init()) )\n\n'
res
<-
res
+
'logout_init <- shinyauthr::logoutServer( id = "logout",active = reactive(credentials()$user_auth)) \n\n'
res
<-
res
+
' blockDeblock <- function(input_list, enable_inputs=F) {\n\n'
res
<-
res
+
' for(x in setdiff(names(input_list),c("login-user_name","login-password","login-button"))){ \n\n'
res
<-
res
+
' if(enable_inputs){ shinyjs::enable(x)} else { shinyjs::disable(x) } } \n\n'
res
<-
res
+
' if(enable_inputs){shinyjs::enable("unlock"); shinyjs::enable("StopPipeline"); shinyjs::enable("close_session")}\n\n'
res
<-
res
+
' else{shinyjs::disable("unlock"); shinyjs::disable("StopPipeline"); shinyjs::disable("close_session")}\n\n'
res
<-
res
+
'}\n\n'
res
<-
res
+
'blockDeblock(isolate(reactiveValuesToList(input)), FALSE)\n\n'
res
<-
res
+
'observeEvent(credentials()$user_auth, {\n\n'
res
<-
res
+
'if (credentials()$user_auth) { blockDeblock(isolate(reactiveValuesToList(input)), TRUE) } else{ blockDeblock(isolate(reactiveValuesToList(input)), FALSE) } }) \n\n'
res
<-
res
+
'\trv <- reactiveValues(textstream = c(""), running = FALSE, timer = reactiveTimer(1000))\n\n'
# Observe query to find user and directory
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment