-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule_training_checkpoint2.R
executable file
·128 lines (90 loc) · 3.33 KB
/
module_training_checkpoint2.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# BUSINESS SCIENCE ----
# DS4B 202-R ----
# AUTHENTICATION & MODULE TRAINING -----
# Version 1
# APPLICATION DESCRIPTION ----
# - Render a Login Dialog Page
# - Dynamically render a UI upon authentication
# - Create a module to produce the login
# - Use the shinyauthr package
library(shiny)
library(shinythemes)
library(shinyjs)
library(tidyverse)
library(shinyauthr) # devtools::install_github("business-science/shinyauthr")
source("modules/module_login.R")
ui <- navbarPage(
title = "Module Training",
theme = shinytheme("flatly"),
collapsible = TRUE,
tabPanel(
useShinyjs(),
title = "Login Module",
h2("No Module"),
div(
id = "login",
style = "width: 500px; max-width: 100%; margin: 0 auto; padding: 20px;",
div(
class = "well",
h2(class = "text-center", "Please Login"),
textInput(inputId = "user_name",
label = tagList(icon("user"), "User Name"),
placeholder = "Enter user name"),
passwordInput(inputId = "password",
label = tagList(icon("unlock-alt"), "Password"),
placeholder = "Enter password"),
div(
class = "text-center",
actionButton(inputId = "login_button", "Log in", class = "btn-primary", style = "color:white;")
)
)
),
uiOutput(outputId = "display_content"),
h2("Using A Module"),
login_ui(id = "login_2", "Modular Login"),
uiOutput(outputId = "display_content_2"),
h2('Using Shiny Auth')
# TODO
)
)
server <- function(input, output, session) {
user_base_tbl <- tibble(
user_name = "user1",
password = "pass1"
)
# NO MODULE ----
validate_password <- eventReactive(input$login_button, {
validate <- FALSE
if (input$user_name == user_base_tbl$user_name && input$password == user_base_tbl$password) {
validate <- TRUE
}
validate
})
output$display_content <- renderUI({
req(validate_password())
div(
class = "well",
id = "success",
h1(class = "page-header", "Stock Analyer", tags$small("by Business Science")),
p(class = "lead", "Page content...")
)
})
# MODULE ----
validate_2 <- callModule(
module = validate_pwd,
id = "login_2",
data = user_base_tbl,
user_col = user_name,
pwd_col = password)
output$display_content_2 <- renderUI({
req(validate_2())
div(
class = "well",
id = "success",
h1(class = "page-header", "Stock Analyer (VALIDATE MODULE)", tags$small("by Business Science")),
p(class = "lead", "Page content...")
)
})
# SHINYAUTHR ----
}
shinyApp(ui, server)