-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
85 lines (69 loc) · 2.13 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
server<- shinyServer(function(input, output, session){
Sys.sleep(.3)
waiter::waiter_hide()
output$suggestion <- renderText({
req(input$file1)
tryCatch(
{
inFile <- input$file1
my_ratings <- readxl::read_excel(inFile$datapath, 1) |>
set_names("food", "rate") |>
drop_na()
},
error = function(e) {
# return a safeError if a parsing error occurs
return("Töltsd fel az értékeléseidet tartalmazó excel fájlt, hogy az eheti menüből tudjunk neked javasolni! :)")
}
)
if (!exists("my_ratings")) {
"Tölts fel az értékeléseidet :)"
}
tryCatch({
my_ratings |>
(\(x) {walk2(x$food, x$rate, \(f, r) {
menu <<- menu |>
mutate(
rate = ifelse(str_detect(str_to_lower(food), str_to_lower(f)), r, rate)
)
})}) ()
s <- menu |>
group_by(delivery_day) |>
filter(!is.na(rate)) |>
arrange(desc(rate)) |>
filter(
(delivery_day == "hétfő" & row_number() <= input$monday) |
(delivery_day == "kedd" & row_number() <= input$tuesday) |
(delivery_day == "szerda" & row_number() <= input$wednesday) |
(delivery_day == "csütörtök" & row_number() <= input$thursday) |
(delivery_day == "péntek" & row_number() <= input$friday)
) |>
group_by(day, category) |>
summarise(food = str_flatten(food, "; ")) |>
ungroup() |>
arrange(day, category) |>
group_by(day) |>
mutate(
food = str_c(
ifelse(row_number() != n(), " ├── ", " └── "),
category, ": ", food
)
) |>
summarise(
food = str_flatten(food, "\n")
) |>
mutate(
food = str_c("\n", str_to_title(day), ":\n", food)
) |>
pull(food)
return(s)
})
})
output$downloadData <- downloadHandler(
filename = function() {
"my_ratings.xlsx"
},
content = function(file) {
openxlsx::write.xlsx(tibble::tibble(food = c("Hortobágyi húsos palacsinta", "Bolognai spagetti", "pulykamell"), rate = c(5, 4, 3)), file)
}
)
})