Update app.R
Browse files
app.R
CHANGED
@@ -18,9 +18,7 @@ ui <- fluidPage(
|
|
18 |
textAreaInput("text", "Or enter French text directly:", value = "",
|
19 |
placeholder = "Type or paste French text here",
|
20 |
width = '100%', height = '200px', resize = "both"),
|
21 |
-
actionButton("analyze", "Analyze")
|
22 |
-
tags$div(id = "progress", style = "display: none; margin-top: 10px;"),
|
23 |
-
tags$style("#progress {font-size: 14px; color: #337ab7;}")
|
24 |
),
|
25 |
|
26 |
mainPanel(
|
@@ -102,20 +100,16 @@ server <- function(input, output, session) {
|
|
102 |
corpus_metrics <- list()
|
103 |
n_files <- length(txt_files)
|
104 |
|
105 |
-
#
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
# Update progress
|
117 |
-
updateProgress(i / n_files * 100)
|
118 |
-
}
|
119 |
|
120 |
# Combine metrics into a data frame
|
121 |
corpus_metrics_df <- do.call(rbind, corpus_metrics)
|
@@ -139,9 +133,10 @@ server <- function(input, output, session) {
|
|
139 |
ggplot(melted_df, aes(x = variable, y = value)) +
|
140 |
geom_boxplot() +
|
141 |
facet_wrap(~ variable, scales = "free_y") +
|
142 |
-
labs(x =
|
143 |
theme_minimal() +
|
144 |
-
theme(axis.text.x =
|
|
|
145 |
}
|
146 |
})
|
147 |
|
@@ -150,28 +145,7 @@ server <- function(input, output, session) {
|
|
150 |
!is.null(results()) && results()$isCorpus
|
151 |
})
|
152 |
outputOptions(output, "isCorpus", suspendWhenHidden = FALSE)
|
153 |
-
|
154 |
-
# JavaScript for updating progress bar
|
155 |
-
session$sendCustomMessage("updateProgress", list(value = 0))
|
156 |
-
observe({
|
157 |
-
session$sendCustomMessage("addProgress", "")
|
158 |
-
})
|
159 |
-
|
160 |
}
|
161 |
|
162 |
-
# JavaScript for updating progress bar
|
163 |
-
js <- "
|
164 |
-
Shiny.addCustomMessageHandler('updateProgress', function(message) {
|
165 |
-
if (message.value === 0) {
|
166 |
-
$('#progress').show().html('Processing... 0%');
|
167 |
-
} else if (message.value === 100) {
|
168 |
-
$('#progress').html('Processing complete!').delay(1000).fadeOut();
|
169 |
-
} else {
|
170 |
-
$('#progress').html('Processing... ' + Math.round(message.value) + '%');
|
171 |
-
}
|
172 |
-
});
|
173 |
-
"
|
174 |
-
tags$head(tags$script(HTML(js)))
|
175 |
-
|
176 |
# Run the application
|
177 |
shinyApp(ui = ui, server = server)
|
|
|
18 |
textAreaInput("text", "Or enter French text directly:", value = "",
|
19 |
placeholder = "Type or paste French text here",
|
20 |
width = '100%', height = '200px', resize = "both"),
|
21 |
+
actionButton("analyze", "Analyze")
|
|
|
|
|
22 |
),
|
23 |
|
24 |
mainPanel(
|
|
|
100 |
corpus_metrics <- list()
|
101 |
n_files <- length(txt_files)
|
102 |
|
103 |
+
# Progress bar for corpus analysis
|
104 |
+
withProgress(message = 'Analyzing corpus', value = 0, {
|
105 |
+
for (i in seq_along(txt_files)) {
|
106 |
+
text <- readLines(txt_files[i], warn = FALSE)
|
107 |
+
corpus_metrics[[i]] <- calculate_metrics(paste(text, collapse = " "))
|
108 |
+
|
109 |
+
# Update progress bar
|
110 |
+
incProgress(1 / n_files)
|
111 |
+
}
|
112 |
+
})
|
|
|
|
|
|
|
|
|
113 |
|
114 |
# Combine metrics into a data frame
|
115 |
corpus_metrics_df <- do.call(rbind, corpus_metrics)
|
|
|
133 |
ggplot(melted_df, aes(x = variable, y = value)) +
|
134 |
geom_boxplot() +
|
135 |
facet_wrap(~ variable, scales = "free_y") +
|
136 |
+
labs(x = NULL, y = "Value", title = "Corpus Analysis - Readability and Cohesion Metrics") +
|
137 |
theme_minimal() +
|
138 |
+
theme(axis.text.x = element_blank(), # Hide x-axis labels for individual boxes
|
139 |
+
axis.ticks.x = element_blank())
|
140 |
}
|
141 |
})
|
142 |
|
|
|
145 |
!is.null(results()) && results()$isCorpus
|
146 |
})
|
147 |
outputOptions(output, "isCorpus", suspendWhenHidden = FALSE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
}
|
149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
# Run the application
|
151 |
shinyApp(ui = ui, server = server)
|