-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.R
101 lines (91 loc) · 3.16 KB
/
app.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
library(shiny)
library(shinyjs)
library(DT)
library(bsicons)
ui <- fluidPage(
includeCSS("www/css/styles.css"),
includeScript("www/js/util.js"),
useShinyjs(),
tags$script(HTML("
$(document).on('shiny:connected', function(event) {
window.resizeTo(1050, 600); // Use optimal window size
});
")),
tags$head(
tags$link(rel="shortcut icon", href = "assets/favicon.ico"),
tags$link(rel ="stylesheet", type="text/css", href = "css/styles.css"),
#--------------------------
#load project title from global.R
tags$title({project_title})
#--------------------------
),
#Home and About page UI components are
#imported in headerUI component
headerUI("header"),
footerUI("footer"),
)
server <- function(input, output,session){
# close the app when session ends
session$onSessionEnded(function() {
# delete all downloaded files on the server after session ended
intermediate_files <- list.files(result_root, full.names = TRUE, pattern ="*.zip|*.pdf")
for (file in intermediate_files) {
tryCatch(
{
file.remove(file)
cat("File", basename(file), "deleted successfully.\n")
},
error = function(e) {
cat("Error Removing file:", e$message, "\n")
}
)
}
stopApp()
})
#---------------------------------------------------
#display the greeting module if not previously shown
greetingModal <- function(){
showModal(
modalDialog(
greetingUI("greeting"),
footer = tagList(
actionButton("continue", "Continue" ,
width = "100%", class="btn-success"
)
)
)
)
}
firstLoad <- reactiveVal(TRUE)
observe({
if(isolate(firstLoad())) {
# display greeting on first load
shinyjs::runjs(sprintf("check_greeting('%s')", "greeting_already_shown"))
# Set to FALSE after first execution
firstLoad(FALSE)
}
})
observeEvent(input$continue,{
removeModal()
message("setting 'greeting_modal_shown' to TRUE")
shinyjs::runjs(' localStorage.setItem("greeting_modal_shown", "shown")')
shinyjs::runjs('let r = (Math.random() + 1).toString(36).substring(7); localStorage.setItem("uid", r);')
})
observeEvent(input$greeting_already_shown, {
if (! grepl("shown", input$greeting_already_shown, fixed=TRUE)){
message("showing greeting modal")
greetingModal()
}
})
#---------------------------------------------------
# We need to pass store to modules that require local storage
store <- reactive({
input$store
})
#---------------------------------------------------
#Home and About page server functions are
#imported in headerServer function
headerServer("header", store=store)
footerServer("footer")
}
shinyApp(ui=ui, server=server)