-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
79 lines (50 loc) · 1.6 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
shinyServer(
# Render data table on home page --------------
output$txn <- renderDataTable({
inFile <- input$file1
if (is.null(inFile)) {
return(NULL)
} else {
this_file <- read_csv(inFile$datapath)[0:5]
this_file$Amount <-
this_file$Amount %>%
as.double()
this_file$Amount <-
sprintf("%.2f", round(this_file$Amount,2))
shinyjs::show(id="findsubs", anim=T, time=1) # reveal "Find My Subscriptions" button
return(this_file)
}
})
# Onclick redirect functionality -----------
onclick(
id = "findsubs",
expr = {
shinyjs::toggleState("findsubs") # disable button to prevent double clicks
shinyjs::show(id="loader_model_results", anim=F) # show loading div
updateTabsetPanel(
session,
inputId = "navigate",
selected = "subs_tab"
)
}
)
# Execute the model and attach results ---------------
observeEvent(input$findsubs, {
output$analyze <- renderDataTable({
data <- analyze(input$file1$datapath)
data_list <- jsonlite::fromJSON(data)
data_out <-
data_list$data %>%
as_tibble() %>%
rename(Name = V1, Amount = V2)
data_out$Amount <-
data_out$Amount %>%
stringr::str_replace("[$]","") %>%
as.double() %>%
round(2)
data_out$Amount <-
sprintf("%.2f", round(data_out$Amount,2))
return(data_out)
})
})
)