pbriss7 commited on
Commit
b8b5684
·
verified ·
1 Parent(s): 3a531d0

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +5 -9
app.R CHANGED
@@ -1,33 +1,29 @@
1
  # Fonction pour filtrer les données
2
  filter_data <- function(data, input, return_columns = NULL) {
3
- # If no column is selected, return an empty data table
4
  if (length(input$column) == 0) {
5
  return(data[0])
6
  }
7
 
 
8
  filtered_data <- data[
9
  Annee_unique >= input$date_range[1] &
10
  Annee_unique <= input$date_range[2]
11
  ]
12
 
13
  pattern <- input$motcle
14
-
15
- # Create a logical vector to store matches across columns
16
  matches <- rep(FALSE, nrow(filtered_data))
17
 
18
- # Check each selected column for matches and combine results with "OR" logic
19
  for (col in input$column) {
20
- if(input$regex){
21
- matches <- matches | grepl(pattern, filtered_data[[col]])
22
  } else {
23
- matches <- matches | grepl(pattern, filtered_data[[col]], fixed = TRUE)
24
  }
25
  }
26
 
27
- # Filter the data based on the combined matches
28
  filtered_data <- filtered_data[matches, ]
29
 
30
- # If return_columns is specified, select only those columns
31
  if (!is.null(return_columns)) {
32
  filtered_data <- filtered_data[, ..return_columns]
33
  }
 
1
  # Fonction pour filtrer les données
2
  filter_data <- function(data, input, return_columns = NULL) {
3
+ # Vérifier si aucune colonne n'est sélectionnée
4
  if (length(input$column) == 0) {
5
  return(data[0])
6
  }
7
 
8
+ # Filtrage par plage de dates
9
  filtered_data <- data[
10
  Annee_unique >= input$date_range[1] &
11
  Annee_unique <= input$date_range[2]
12
  ]
13
 
14
  pattern <- input$motcle
 
 
15
  matches <- rep(FALSE, nrow(filtered_data))
16
 
 
17
  for (col in input$column) {
18
+ if (input$regex) {
19
+ matches <- matches | grepl(pattern, filtered_data[[col]], ignore.case = TRUE)
20
  } else {
21
+ matches <- matches | grepl(pattern, filtered_data[[col]], fixed = TRUE, ignore.case = TRUE)
22
  }
23
  }
24
 
 
25
  filtered_data <- filtered_data[matches, ]
26
 
 
27
  if (!is.null(return_columns)) {
28
  filtered_data <- filtered_data[, ..return_columns]
29
  }