this repo has no description
1load("code/big_question_tag_df.rda")
2
3#head(big_question_tag_df)
4#summary(big_question_tag_df)
5#view(big_question_tag_df)
6
7#Remove rows where Tags = NA
8only_tag <- big_question_tag_df |>
9 filter(Tags != "NA")
10#view(only_tag)
11
12tagged_ams <- only_tag |>
13 filter(Source == "AMS")
14
15tagged_cbms <- only_tag |>
16 filter(Source == "CBMS")
17
18#view(tagged_ams)
19#view(tagged_cbms)
20
21#All questions by source
22ams_ques <- big_question_tag_df |>
23 filter(Source == "AMS")
24
25cbms_ques <- big_question_tag_df |>
26 filter(Source == "CBMS")
27
28ipeds_ques <- big_question_tag_df |>
29 filter(Source == "IPEDS")
30
31#Tokenization and wordcloud per source
32#AMS
33tidy_ams_ques <- ams_ques |>
34 unnest_tokens(word, Questions) |>
35 anti_join(stop_words) |>
36 filter(!str_detect(word, "^[0-9]+$"))
37
38word_counts_ams <- tidy_ams_ques |>
39 count(word, sort = TRUE) |>
40 filter(n > 0)
41
42#view(word_counts_ams)
43
44#----CBMS
45tidy_cbms_ques <- cbms_ques |>
46 unnest_tokens(word, Questions) |>
47 anti_join(stop_words) |>
48 filter(!str_detect(word, "^[0-9]+$"))
49
50word_counts_cbms <- tidy_cbms_ques |>
51 count(word, sort = TRUE) |>
52 filter(n > 5) |>
53 filter(!str_detect(word, "_|b2|b1|e1|f1|e2|e.g|ii"))
54
55view(word_counts_cbms)
56
57#----IPEDS
58tidy_ipeds_ques <- ipeds_ques |>
59 unnest_tokens(word, Questions) |>
60 anti_join(stop_words) |>
61 filter(!str_detect(word, "^[0-9]+$"))
62
63word_counts_ipeds <- tidy_ipeds_ques |>
64 count(word, sort = TRUE) |>
65 filter(n > 5) |>
66 filter(!str_detect(word, "e.g"))
67
68view(word_counts_ipeds)
69
70library("wordcloud2")
71library("shiny")
72library("DT")
73library("stringr")
74
75#AMS
76my_palette = c("#355070",
77 "#6d597a",
78 "#b56576",
79 "#e56b6f",
80 "#eaac8b")
81
82ams_wc = wordcloud2(
83 word_counts_ams,
84 color = rep_len(my_palette,
85 nrow(word_counts_ams)))
86
87# Interactive Shiny App for AMS Questions
88ui = fluidPage(
89 titlePanel("Interactive Word Cloud - AMS Survey Questions"),
90 tags$script(HTML(
91 "$(document).on('click', '#canvas', function() {
92 word = $('#wcLabel').text();
93 Shiny.onInputChange('clicked_word', word);
94 });")),
95 wordcloud2Output("wordcloud"),
96 br(),
97 h3("Questions containing the selected word:"),
98 DTOutput("filtered_tbl")
99)
100
101server = function(input, output) {
102 output$wordcloud = renderWordcloud2(ams_wc)
103
104 filtered_questions = reactive({
105 if(is.null(input$clicked_word)) {
106 # Show empty table initially
107 return(ams_ques[0,])
108 }
109
110 clicked_word = str_remove(input$clicked_word, ":[0-9]+$")
111
112 ams_ques %>%
113 filter(str_detect(tolower(Questions), tolower(clicked_word))) %>%
114 select(Questions, Tags, Source, everything())
115 })
116
117 output$filtered_tbl = renderDT(
118 filtered_questions(),
119 options = list(pageLength = 10, scrollX = TRUE),
120 rownames = FALSE
121 )
122}
123
124#shinyApp(ui, server)
125
126# CBMS Interactive App
127cbms_wc = wordcloud2(
128 word_counts_cbms,
129 color = rep_len(my_palette,
130 nrow(word_counts_cbms)))
131
132ui_cbms = fluidPage(
133 titlePanel("Interactive Word Cloud - CBMS Survey Questions"),
134 tags$script(HTML(
135 "$(document).on('click', '#canvas', function() {
136 word = $('#wcLabel').text();
137 Shiny.onInputChange('clicked_word', word);
138 });")),
139 wordcloud2Output("wordcloud"),
140 br(),
141 h3("Questions containing the selected word:"),
142 DTOutput("filtered_tbl")
143)
144
145server_cbms = function(input, output) {
146 output$wordcloud = renderWordcloud2(cbms_wc)
147
148 filtered_questions = reactive({
149 if(is.null(input$clicked_word)) {
150 return(cbms_ques[0,])
151 }
152
153 clicked_word = str_remove(input$clicked_word, ":[0-9]+$")
154
155 cbms_ques %>%
156 filter(str_detect(tolower(Questions), tolower(clicked_word))) %>%
157 select(Questions, Tags, Source, everything())
158 })
159
160 output$filtered_tbl = renderDT(
161 filtered_questions(),
162 options = list(pageLength = 10, scrollX = TRUE),
163 rownames = FALSE
164 )
165}
166
167# Uncomment to run CBMS app:
168# shinyApp(ui_cbms, server_cbms)
169
170# IPEDS Interactive App
171ipeds_wc = wordcloud2(
172 word_counts_ipeds,
173 color = rep_len(my_palette,
174 nrow(word_counts_ipeds)))
175
176ui_ipeds = fluidPage(
177 titlePanel("Interactive Word Cloud - IPEDS Survey Questions"),
178 tags$script(HTML(
179 "$(document).on('click', '#canvas', function() {
180 word = $('#wcLabel').text();
181 Shiny.onInputChange('clicked_word', word);
182 });")),
183 wordcloud2Output("wordcloud"),
184 br(),
185 h3("Questions containing the selected word:"),
186 DTOutput("filtered_tbl")
187)
188
189server_ipeds = function(input, output) {
190 output$wordcloud = renderWordcloud2(ipeds_wc)
191
192 filtered_questions = reactive({
193 if(is.null(input$clicked_word)) {
194 return(ipeds_ques[0,])
195 }
196
197 clicked_word = str_remove(input$clicked_word, ":[0-9]+$")
198
199 ipeds_ques %>%
200 filter(str_detect(tolower(Questions), tolower(clicked_word))) %>%
201 select(Questions, Tags, Source, everything())
202 })
203
204 output$filtered_tbl = renderDT(
205 filtered_questions(),
206 options = list(pageLength = 10, scrollX = TRUE),
207 rownames = FALSE
208 )
209}
210
211# Uncomment to run IPEDS app:
212# shinyApp(ui_ipeds, server_ipeds)