Skip to content

Commit

Permalink
feat(data-viz): add validator for input categ_variables
Browse files Browse the repository at this point in the history
  • Loading branch information
juliendiot42 committed Sep 24, 2024
1 parent 062d25f commit 88c2c76
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/fun/func_data-viz.R
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ plot_warning <- function(data, x_var, y_var, col_var) {
warnings_messages <- c(warnings_messages,
"Categorical variable with a large amount of levels is detected, plot may not render correctly."
)
break()
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/server/server_data_viz.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ output$data_viz_UI <- renderUI({
})


data_viz_file_validator <- InputValidator$new()
data_viz_file_validator$add_rule("categ_variables", function(x) {
data <- raw_data_from_file()
must_be_categorical_var <- colnames(data)[sapply(colnames(data), function(var) {
numeric_values <- as.numeric(data[, var])
any(is.na(numeric_values))
})]
if (!all(must_be_categorical_var %in% x)) {
missing_var <- must_be_categorical_var[!must_be_categorical_var %in% x]
return(paste0(
"`", paste0(missing_var, collapse = "`, `"),
"`, must be categorical"
)
)
}
return(NULL)
})
data_viz_file_validator$enable()

raw_data_from_file <- reactive({
if (is.null(input$file_data_viz)) {
return(NULL)
Expand Down

0 comments on commit 88c2c76

Please sign in to comment.