-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcommentSearch.R
190 lines (138 loc) · 6.63 KB
/
commentSearch.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
output$commentSearchSelector <- renderUI({
# I may be able to have more than one on the screen at once
# let's look at that some time
# 1. top 6 themes- preprocess
if(!isTruthy(returnTopComments(passData()[["currentData"]],
1 : 6,
"Both",
categoriesTable())[["return_table"]])){
return(p("No tagged data available, please expand your search"))
}
comment_table <- returnTopComments(passData()[["currentData"]],
1 : 6,
"Both",
categoriesTable())[["return_table"]]
list_names <- comment_table$Number
names(list_names) = paste0(comment_table$Super, ":<br>", comment_table$Category)
# 2. Criticality- preprocess
criticality_choices <- list("Highly Complimentary" = 3, "Fairly Complimentary" = 2,
"Mildly Complimentary" = 1, "Mildly critical" = -1,
"Fairly Critical" = -2, "Highly Critical" = -3)
# 4. Pre selected search- preprocess
tagList(
box(width = 12, downloadButton("downloadCommentSearch", "Download filtered comments")),
box(width = 6, height = 130, checkboxGroupInput("filterCommentsBy", "Filter comments by...",
choices = c("Text search", "Criticality", "Themes"),
selected = "Text search")),
box(width = 6, height = 130, actionButton("showTimeline", "Show timeline")),
box(width = 12,
# 1. Search
conditionalPanel("input.filterCommentsBy.includes('Text search')",
textInput("searchTextInclude", "Enter search terms separated by commas"),
textInput("textSearchExclude", HTML("Enter terms to <em>exclude</em> separated by commas"))),
# 2. criticality levels
conditionalPanel("input.filterCommentsBy.includes('Criticality')",
checkboxGroupButtons("criticalityLevels", "Criticality levels (all selected by default)",
choices = criticality_choices,
selected = criticality_choices, status = "default", size = "lg",
direction = "vertical", justified = FALSE, individual = FALSE)),
# 3. top 6 themes
conditionalPanel("input.filterCommentsBy.includes('Themes')",
checkboxGroupButtons("topSixThemes", "Top six themes (all selected by default)",
choices = list_names,
selected = list_names, status = "default", size = "lg",
direction = "vertical", justified = FALSE, individual = FALSE))
)
)
})
output$commentSearchOutput <- renderUI({
tagList(
fluidRow(
column(4, uiOutput("commentSearchSelector")),
column(8, box(width = 12,
fluidRow(
column(6, h2("What could we do better?"), htmlOutput("showImprove")),
column(6, h2("What did we do well?"), htmlOutput("showBest"))
)
)
)
)
)
})
observeEvent(input$showTimeline, {
showModal(
modalDialog(
textOutput("beeswarmText"),
plotOutput("beeswarmComments", click = "beeswarm_click"),
size = "l")
)
})
output$showImprove <- renderText({
text_df <- returnSearchText(passData()[["currentData"]], "Improve",
filterCommentsBy = input$filterCommentsBy,
searchTextInclude = input$searchTextInclude,
textSearchExclude = input$textSearchExclude,
criticalityLevels = input$criticalityLevels,
topSixThemes = input$topSixThemes)
paste0("<p>", text_df$Improve, " (",
text_df$Location, ")</p>", collapse = "")
})
output$showBest <- renderText({
text_df <- returnSearchText(passData()[["currentData"]], "Best",
filterCommentsBy = input$filterCommentsBy,
searchTextInclude = input$searchTextInclude,
textSearchExclude = input$textSearchExclude,
criticalityLevels = input$criticalityLevels,
topSixThemes = input$topSixThemes)
paste0("<p>", text_df$Best, " (",
text_df$Location, ")</p>", collapse = "")
})
# this is being cached so the plot click can access it
beeswarmGraph <- reactive({
combined <- rbind(
passData()[["currentData"]] %>%
select(Date, Imp1, ImpCrit, Improve, Location) %>%
gather(key, value, -Date, -ImpCrit, -Improve, -Location) %>%
rename(Crit = ImpCrit, Comment = Improve) %>%
mutate(Crit = -Crit),
passData()[["currentData"]] %>%
select(Date, Best1, BestCrit, Best, Location) %>%
gather(key, value, -Date, -BestCrit, -Best, -Location) %>%
rename(Crit = BestCrit, Comment = Best)
)
if(!is.null(input$searchTextInclude)){
combined <- combined %>%
filter(grepl(input$searchTextInclude, Comment))
}
combined %>%
filter(!is.na(Crit), !is.na(Comment)) %>%
filter(value %in% input$topSixThemes) %>%
filter(Crit %in% input$criticalityLevels) %>%
mutate(Crit = factor(Crit, levels = c(-3, -2, -1, 1, 2, 3))) %>%
mutate(y_axis = 0, y_axis = jitter(y_axis))
})
output$beeswarmComments <- renderPlot({
beeswarmGraph() %>%
ggplot(aes(x = Date, y = y_axis, colour = Crit)) +
geom_point() +
scale_colour_brewer(palette = "Spectral") +
theme(axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank())
})
output$beeswarmText <- renderText({
beeswarm_df <- nearPoints(beeswarmGraph(), input$beeswarm_click, threshold = 100, maxpoints = 1)
req(nrow(beeswarm_df) > 0)
with(beeswarm_df, paste0(Comment, " (", Location, ")"))
})
output$downloadCommentSearch <- downloadHandler(
filename = "SearchComments.docx",
content = function(file){
params <- generate_rmd_parameters()
render("reports/SearchComments.Rmd", output_format = "word_document",
quiet = TRUE, params = params,
envir = new.env(parent = globalenv()))
# copy docx to 'file'
file.copy("reports/SearchComments.docx", file, overwrite = TRUE)
}
)