-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
136 lines (118 loc) · 3.67 KB
/
server.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
129
130
131
132
133
134
135
136
# Define server logic required
#==========================================================================================
server <- function(input, output, session) {
onStop(function(){
resetAuthSessionVariables(session)
})
#page management
session$userData$page <- reactiveVal(NULL)
loadedSideUI <- reactiveVal(FALSE)
loadedMainUI <- reactiveVal(FALSE)
if(appConfig$auth){
#auth mode
auth_info <- reactiveVal(NULL)
if(appConfig$auth_ui){
#auth with UI
credentials <- authLoginServer(
id = "login",
config = appConfig,
log_out = reactive(logout_init())
)
#call the logout module with reactive trigger to hide/show
logout_init <- shinyauthr::logoutServer(
id = "logout",
active = reactive(credentials()$user_auth)
)
observe({
if (credentials()$user_auth) {
info = credentials()$auth_info
info$logged <- credentials()$user_auth
auth_info(info)
if(!is.null(auth_info())){
initAuthSessionVariables(session, auth_info())
INFO("Set-up shiny-calipseo in auth mode")
shinyjs::removeClass(selector = "body", class = "sidebar-collapse")
shinyjs::show(selector = "header")
loadModuleServers(appConfig, pool) #TODO pass auth_info to all modules?
}
} else {
shinyjs::addClass(selector = "body", class = "sidebar-collapse")
shinyjs::hide(selector = "header")
}
})
}else{
#auth without UI
shinyjs::removeClass(selector = "body", class = "sidebar-collapse")
shinyjs::show(selector = "header")
#TODO auth through URL token passing?
#Shiny proxy?
}
}else{
#anonymous usage
observe({
INFO("Set-up geoflow-shiny in anonymous mode")
#shinyjs::removeClass(selector = "body", class = "sidebar-collapse")
#shinyjs::show(selector = "header")
loadModuleServers(appConfig, pool)
})
}
#side UI
#output$side_ui <- renderUI({
# print(loadedSideUI())
# if(!loadedSideUI()){
# loadedSideUI(TRUE)
# if(appConfig$auth){
# if(appConfig$auth_ui){
# req(credentials()$user_auth)
# sidebarMenuFromModules(appConfig)
# }else{
# sidebarMenuFromModules(appConfig)
# }
# }else{
# sidebarMenuFromModules(appConfig)
# }
# }
#})
#main UI
#output$main_ui <- renderUI({
# print(loadedMainUI())
# if(!loadedMainUI()){
# loadedMainUI(TRUE)
# if(appConfig$auth){
# if(appConfig$auth_ui){
# req(credentials()$user_auth)
# loadModuleUIs(appConfig)
# }else{
# loadModuleUIs(appConfig)
# }
# }else{
# loadModuleUIs(appConfig)
# }
# }
#})
observe({
currentPage <- NA
#look if there is a page in URL, if yes use it
query <- parseQueryString(session$clientData$url_search)
if (!is.null(query$page)) {
currentPage <- query$page
cat(sprintf("Current page from URL %s\n", currentPage))
}else{
if (!is.null(session$userData$page())) {
currentPage <- session$userData$page()
cat(sprintf("Current page from userData %s\n", currentPage))
}
}
if (!is.na(currentPage)) {
isolate({updateTabItems(session, "calipseo-tabs", gsub("-", "_", currentPage))})
}
})
observe({
#Update PageUrl
if(!is.null(input$`calipseo-tabs`)) if(input$`calipseo-tabs` != "home") {
PageUrl <- gsub('_', '-', input$`calipseo-tabs`)
session$userData$page(PageUrl)
updatePageUrl(PageUrl, session)
}
})
}