|
|
|
|
|
|
|
filter_data <- function(data, input, return_columns = NULL) { |
|
|
|
if (length(input$column) == 0) { |
|
return(data[0]) |
|
} |
|
|
|
filtered_data <- data[ |
|
Annee_unique >= input$date_range[1] & |
|
Annee_unique <= input$date_range[2] |
|
] |
|
|
|
pattern <- input$motcle |
|
|
|
|
|
matches <- rep(FALSE, nrow(filtered_data)) |
|
|
|
|
|
for (col in input$column) { |
|
if(input$regex){ |
|
matches <- matches | grepl(pattern, filtered_data[[col]]) |
|
} else { |
|
matches <- matches | grepl(pattern, filtered_data[[col]], fixed = TRUE) |
|
} |
|
} |
|
|
|
|
|
filtered_data <- filtered_data[matches, ] |
|
|
|
|
|
if (!is.null(return_columns)) { |
|
filtered_data <- filtered_data[, ..return_columns] |
|
} |
|
|
|
return(filtered_data) |
|
} |
|
|
|
plot_histogram <- function(data_frame) { |
|
if ("Annee_unique" %in% names(data_frame) && nrow(data_frame) > 0) { |
|
min_year <- min(na.omit(data_frame[, Annee_unique])) |
|
max_year <- max(na.omit(data_frame[, Annee_unique])) |
|
breaks_hist <- seq(min_year, max_year, length.out = input$num_breaks + 1) |
|
|
|
if (input$dist_type == "raw") { |
|
hist(data_frame()[, Annee_unique], |
|
main = "Distribution brute des notices", |
|
xlab = "Année", |
|
ylab = "Nombre", |
|
border = "blue", |
|
col = "lightblue", |
|
breaks = breaks_hist) |
|
} else { |
|
|
|
filtered_counts <- hist(data_frame[, Annee_unique], plot=FALSE, breaks=breaks_hist)$counts |
|
total_counts <- hist(data[data$Annee_unique %in% data_frame[, Annee_unique], Annee_unique], plot=FALSE, breaks=breaks_hist)$counts |
|
relative_counts <- ifelse(total_counts == 0, 0, filtered_counts / total_counts) |
|
|
|
|
|
names_for_bars <- round(seq(min_year, max_year, length.out = length(relative_counts))) |
|
|
|
barplot(relative_counts, |
|
main = "Distribution relative des notices", |
|
xlab = "Année", |
|
ylab = "Fréquence relative", |
|
border = "blue", |
|
col = "lightblue", |
|
space = 0, |
|
names.arg = names_for_bars) |
|
} |
|
} else { |
|
plot.new() |
|
title(main = "No data available for the selected criteria") |
|
} |
|
} |
|
|
|
inst_ext_f <- function(extension) { |
|
if(!extension %in% rownames(installed.packages())) { |
|
install.packages(extension, dependencies = TRUE) |
|
} |
|
require(extension, character.only = TRUE) |
|
} |
|
|
|
|