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