-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathallCommentsTab.R
129 lines (93 loc) · 3.48 KB
/
allCommentsTab.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
output$allImproveComments = renderText({
df <- allComments(comment_data = passData()[["currentData"]],
category_criticality = input$sortCategoryCriticality,
improve_do_well = "Improve",
category_table = categoriesTable())
if(input$sortCategoryCriticality == "Category"){
finalText = map(unique(df$Super), function(x) {
commentsFrame = df %>%
filter(Super == x) %>%
ungroup() %>%
select(Improve, Location) %>%
set_names(c("Comment", "Location"))
paste0("<h3>", x, "</h3>",
paste0("<p>", gsub("[<>]", "", commentsFrame$Comment), " (",
commentsFrame$Location, ")</p>", collapse = "")
)
})
return(unlist(finalText))
} else {
nameVector = c("Mildly critical", "Somewhat critical", "Very critical")
finalText = map(3 : 1, function(x) {
commentsFrame = df %>%
filter(ImpCrit == x) %>%
select(Improve, Location) %>%
set_names(c("Comment", "Location"))
if(nrow(commentsFrame) > 0){
paste0("<h3>", nameVector[x], "</h3>",
paste0("<p>", commentsFrame$Comment, " (",
commentsFrame$Location, ")</p>", collapse = "")
)
}
})
return(unlist(finalText))
}
})
output$allBestComments = renderText({
df <- allComments(comment_data = passData()[["currentData"]],
category_criticality = input$sortCategoryCriticality,
improve_do_well = "Best",
category_table = categoriesTable())
if(input$sortCategoryCriticality == "Category"){
finalText <- map(unique(df$Super), function(x) {
commentsFrame <- df %>%
filter(Super == x) %>%
ungroup() %>%
select(Best, Location) %>%
set_names(c("Comment", "Location"))
paste0("<h3>", x, "</h3>",
paste0("<p>", commentsFrame$Comment, " (",
commentsFrame$Location, ")</p>", collapse = "")
)
})
return(unlist(finalText))
} else {
nameVector = c("Mildly complimentary", "Somewhat complimentary", "Very complimentary")
finalText = map(3 : 1, function(x) {
commentsFrame = df %>%
filter(BestCrit == x) %>%
select(Best, Location) %>%
set_names(c("Comment", "Location"))
if(nrow(commentsFrame) > 0){
paste0("<h3>", nameVector[x], "</h3>",
paste0("<p>", commentsFrame$Comment, " (",
commentsFrame$Location, ")</p>", collapse = "")
)
}
})
return(unlist(finalText))
}
})
# download all comments button
output$downloadAllComments <- downloadHandler(
filename = "AllComments.docx",
content = function(file){
if(nrow(passData()[["currentData"]]) > 10000){
showModal(
modalDialog(
title = "Error!",
HTML("Too many comments, please reduce your selection"),
easyClose = TRUE
)
)
return()
}
# Set up parameters to pass to Rmd document
params <- generate_rmd_parameters()
render("reports/AllComments.Rmd", output_format = "word_document",
quiet = TRUE, params = params,
envir = new.env(parent = globalenv()))
# copy docx to 'file'
file.copy("reports/AllComments.docx", file, overwrite = TRUE)
}
)