Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add shinyvalidate to tmg #498

Merged
merged 75 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
1fddb7b
first batch of modules
mhallal1 Dec 22, 2022
78d57eb
Merge 1fddb7bd4e58fcae9cfc17f854d6e460c9830bcd into a9a1b87311725e57f…
mhallal1 Dec 22, 2022
a7699fb
[skip actions] Restyle files
github-actions[bot] Dec 22, 2022
e320e08
mb outliers
BLAZEWIM Dec 22, 2022
ef5693c
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Dec 22, 2022
5646d1c
clean missing data
mhallal1 Dec 23, 2022
dc26b82
outliers fixes
mhallal1 Dec 23, 2022
7fd3aae
outliers fixes2
mhallal1 Dec 23, 2022
26876f3
crosstable
mhallal1 Dec 23, 2022
4c6bb13
lintr
mhallal1 Dec 23, 2022
d231b17
NEWS + Description
mhallal1 Dec 23, 2022
5b6ea87
review Nik
mhallal1 Dec 23, 2022
eb67682
Merge branch 'main' into 420_shinyvalidate@main
mhallal1 Dec 29, 2022
aac3984
modules by AC (#499)
chlebowa Dec 29, 2022
a0ab9fd
Apply suggestions from code review
mhallal1 Dec 30, 2022
a5cf40d
Apply suggestions from code review
mhallal1 Dec 30, 2022
66f38df
tm_data_table
mhallal1 Dec 30, 2022
3e4a37b
bivariate
mhallal1 Dec 30, 2022
b200727
tm_g_association
mhallal1 Dec 30, 2022
adfb1ac
Update R/tm_missing_data.R
mhallal1 Dec 30, 2022
0ade6b3
Merge branch 'main' into 420_shinyvalidate@main
mhallal1 Dec 30, 2022
974d4b4
minor style fix
Jan 2, 2023
d545a07
remove theme validation
Jan 2, 2023
20b28b6
remove crule to rely on teal
Jan 2, 2023
761a080
add namespace prefix tor crule and restyle
Jan 2, 2023
87fdf9c
fix pkgdown
Jan 2, 2023
9abbe9c
review
mhallal1 Jan 2, 2023
b150529
merge main
mhallal1 Jan 2, 2023
efc5ebf
roll back crule
Jan 2, 2023
954c1b1
roll back crule
Jan 2, 2023
ed55a7d
Merge branch '420_shinyvalidate@main' of github.com:insightsengineeri…
Jan 2, 2023
24e3da4
improve validation in scatterplot
Jan 2, 2023
5bbf12d
additional validation in tm_g_scatterplot
Jan 2, 2023
a2686e6
enhance example in tm_g_bivariate
Jan 2, 2023
9cd1d9e
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Jan 2, 2023
32eaca7
change validation messages in tm_t_crosstable
Jan 2, 2023
4b2381d
roll back crule in tm_outliers
Jan 2, 2023
a205240
update output in tm_outliers
Jan 2, 2023
a18d363
update tm_g_scatterplot
Jan 3, 2023
b186f49
roll back crule in tm_g_response
Jan 3, 2023
796cd4f
improve rule in tm_g_outliers
Jan 3, 2023
d8285d2
tm_g_response
Jan 3, 2023
c5c0231
apply review to tm_a_pca
Jan 3, 2023
226f222
fix facetting bug
Jan 3, 2023
4753cb3
improve validation in tm_g_scatterplot
Jan 3, 2023
fc9818a
argument checks in tm_g_bivariate and tm_g_scatterplot
Jan 3, 2023
7e87056
message
Jan 4, 2023
4e385d4
fix rule in tm_t_crosstable
Jan 4, 2023
4cfe816
fix validation in tm_g_distribution
Jan 4, 2023
8ac883b
Update R/tm_g_scatterplot.R
Jan 4, 2023
28c2f1d
Apply suggestions from code review
Jan 4, 2023
2735fa9
fix vingette
Jan 4, 2023
1399311
update argument checks in tm_outliers
Jan 4, 2023
0c91c93
update error message in tm_outliers
Jan 4, 2023
98f0fdf
improve error message in tm_outliers
Jan 4, 2023
8268b9c
Fix strata_var vs test (#506)
gogonzo Jan 5, 2023
03bdf10
fix validtion in tm_g_distribution
Jan 5, 2023
9bc1959
improve reactivity in tm_outlier
Jan 5, 2023
fbefb01
bug fix
Jan 5, 2023
010aeda
improve message in tm_outliers
Jan 5, 2023
69ef244
Remove some deprecated ggplot2 functions (#507)
Jan 6, 2023
0707b91
Apply suggestions from code review
Jan 6, 2023
3e429fb
fix response
Jan 6, 2023
5ff28f3
* fix a message "summary_table not found"
gogonzo Jan 6, 2023
078c687
response
Jan 6, 2023
e035d59
Merge branch '420_shinyvalidate@main' of github.com:insightsengineeri…
gogonzo Jan 6, 2023
5afd497
scatterplot fix
Jan 6, 2023
22dce7e
Merge branch '420_shinyvalidate@main' of https://github.com/insightse…
Jan 6, 2023
292d2cb
outliers
Jan 6, 2023
dd4a596
bivariate fix
Jan 6, 2023
475f24e
Apply suggestions from code review
Jan 6, 2023
18cbb43
pca improve validation message
Jan 6, 2023
47a5724
fix distribution
Jan 6, 2023
9a423bf
Remove extract input from dist (#509)
Jan 6, 2023
e39ec80
Fix des outliers@420 shinyvalidate@main (#511)
gogonzo Jan 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Imports:
magrittr,
scales,
shinyjs,
shinyvalidate,
shinyWidgets,
stats,
stringr,
Expand Down Expand Up @@ -88,4 +89,4 @@ Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Added `parent_dataname` argument to `tm_variable_browser` and `tm_missing_data` to allow specification of parent dataset for these modules.
* Improved UI labels and plot panel title in `tm_g_association`.
* Added inputs `tm_variable_browser` module for text size and plot theme.
* Updated encodings input checks to use `shinyvalidate::InputValidator` instead of `shiny::validate` for better UI experience.

### Bug fixes
* Fixed a bug in `tm_g_scatterplot` when selected x and y facets were the same.
Expand Down
12 changes: 7 additions & 5 deletions R/tm_data_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,18 @@ srv_data_table <- function(id,
server_rendering) {
moduleServer(id, function(input, output, session) {
output$data_table <- DT::renderDataTable(server = server_rendering, {
variables <- input$variables
df <- data[[dataname]]()

validate(need(variables, "need valid variable names"))
iv <- shinyvalidate::InputValidator$new()
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved
iv$add_rule("variables", shinyvalidate::sv_required("Please select valid variable names"))
iv$add_rule("variables", ~ if (!all((.) %in% names(df))) "Not all selected variables exist in the data")
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved
iv$enable()
validate_inputs(iv)
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved

df <- data[[dataname]]()
variables <- input$variables

validate(need(df, paste("data", dataname, "is empty")))
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved

validate(need(all(variables %in% names(df)), "not all selected variables exist"))

dataframe_selected <- if (if_distinct()) {
dplyr::count(df, dplyr::across(tidyselect::all_of(variables)))
} else {
Expand Down
40 changes: 27 additions & 13 deletions R/tm_g_association.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,31 @@ srv_tm_g_association <- function(id,
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
checkmate::assert_class(data, "tdata")
moduleServer(id, function(input, output, session) {
overlap_vars <- function(value) {
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved
if (length(selector_list()$ref()$select) != 0 &&
selector_list()$ref()$select %in% selector_list()$vars()$select) {
"Associated variables and reference variable cannot overlap"
}
}
selector_list <- teal.transform::data_extract_multiple_srv(
data_extract = list(ref = ref, vars = vars),
datasets = data
datasets = data,
select_validation_rule = list(
ref = shinyvalidate::compose_rules(
shinyvalidate::sv_required("At least one reference variable needs to be selected."),
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved
overlap_vars
),
vars = overlap_vars
)
)

iv_r <- reactive({
iv <- shinyvalidate::InputValidator$new()
iv$add_rule("distribution_theme", shinyvalidate::sv_required("Please select a theme"))
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
iv$add_rule("association_theme", shinyvalidate::sv_required("Please select a theme"))
teal.transform::compose_and_enable_validators(iv, selector_list)
})

anl_merged_input <- teal.transform::merge_expression_srv(
datasets = data,
selector_list = selector_list,
Expand All @@ -245,12 +265,7 @@ srv_tm_g_association <- function(id,
)

output_q <- reactive({
validate({
need(
!is.null(selector_list()$ref()) && !is.null(selector_list()$vars()),
"Please select reference and associated variables"
)
})
teal::validate_inputs(iv_r())

ANL <- merged$anl_q_r()[["ANL"]] # nolint
teal::validate_has_data(ANL, 3)
Expand All @@ -266,8 +281,7 @@ srv_tm_g_association <- function(id,
distribution_theme <- input$distribution_theme
association_theme <- input$association_theme

validate(need(ref_name, "need at least one variable selected"))

req(ref_name)
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved
is_scatterplot <- is.numeric(ANL[[ref_name]]) && any(vapply(ANL[vars_names], is.numeric, logical(1)))
if (is_scatterplot) {
shinyjs::show("alpha")
Expand All @@ -281,9 +295,6 @@ srv_tm_g_association <- function(id,
size <- 2
}

validate(need(!(ref_name %in% vars_names), "associated variables and reference variable cannot overlap"))
validate(need(!is.null(distribution_theme) && !is.null(association_theme), "Please select a theme."))

teal::validate_has_data(ANL[, c(ref_name, vars_names)], 3, complete = TRUE, allow_inf = FALSE)

# reference
Expand Down Expand Up @@ -417,7 +428,10 @@ srv_tm_g_association <- function(id,
)
})

plot_r <- shiny::reactive(output_q()[["p"]])
plot_r <- shiny::reactive({
shiny::req(iv_r()$is_valid())
output_q()[["p"]]
})

pws <- teal.widgets::plot_with_settings_srv(
id = "myplot",
Expand Down
29 changes: 21 additions & 8 deletions R/tm_g_bivariate.R
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,26 @@ srv_g_bivariate <- function(id,
color = color, fill = fill, size = size
)

selector_list <- teal.transform::data_extract_multiple_srv(data_extract, data)
x_y_selection <- function(value) {
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved
if (length(selector_list()$x()$select) == 0 && length(selector_list()$y()$select) == 0) {
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved
"Please select at least one of x-variable or y-variable"
}
}

selector_list <- teal.transform::data_extract_multiple_srv(
data_extract = data_extract,
datasets = data,
select_validation_rule = list(
x = x_y_selection,
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved
y = x_y_selection
)
)

iv_r <- reactive({
iv <- shinyvalidate::InputValidator$new()
iv$add_rule("ggtheme", shinyvalidate::sv_required("Please select a theme"))
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved
teal.transform::compose_and_enable_validators(iv, selector_list)
})
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved

anl_merged_input <- teal.transform::merge_expression_srv(
selector_list = selector_list,
Expand All @@ -383,12 +402,7 @@ srv_g_bivariate <- function(id,
)

output_q <- reactive({
validate({
need(
length(merged$anl_input_r()$columns_source$x) > 0 || length(merged$anl_input_r()$columns_source$y) > 0,
"x-variable and y-variable aren't correctly specified. At least one should be valid."
)
})
teal::validate_inputs(iv_r())

ANL <- merged$anl_q_r()[["ANL"]] # nolint
teal::validate_has_data(ANL, 3)
Expand Down Expand Up @@ -450,7 +464,6 @@ srv_g_bivariate <- function(id,


teal::validate_has_data(ANL[, c(x_name, y_name)], 3, complete = TRUE, allow_inf = FALSE)
validate(need(!is.null(ggtheme), "Please select a theme."))

cl <- bivariate_plot_call(
data_name = "ANL",
Expand Down
23 changes: 16 additions & 7 deletions R/tm_g_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,20 @@ srv_g_response <- function(id,
moduleServer(id, function(input, output, session) {
data_extract <- list(response = response, x = x, row_facet = row_facet, col_facet = col_facet)

selector_list <- teal.transform::data_extract_multiple_srv(data_extract, data)
selector_list <- teal.transform::data_extract_multiple_srv(
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved
data_extract = data_extract,
datasets = data,
select_validation_rule = list(
response = shinyvalidate::sv_required("Please define a column for the response variable"),
x = shinyvalidate::sv_required("Please define a column for X variable")
)
)

iv_r <- reactive({
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved
iv <- shinyvalidate::InputValidator$new()
iv$add_rule("ggtheme", shinyvalidate::sv_required("Please select a theme"))
teal.transform::compose_and_enable_validators(iv, selector_list)
})

anl_merged_input <- teal.transform::merge_expression_srv(
selector_list = selector_list,
Expand All @@ -254,15 +267,13 @@ srv_g_response <- function(id,
)

output_q <- reactive({
teal::validate_inputs(iv_r())

qenv <- merged$anl_q_r()
ANL <- qenv[["ANL"]] # nolint
resp_var <- as.vector(merged$anl_input_r()$columns_source$response)
x <- as.vector(merged$anl_input_r()$columns_source$x)

validate(need(!identical(resp_var, character(0)), "Please define a valid column for the response variable"))
validate(need(!identical(x, character(0)), "Please define a valid column for the X-variable"))
validate(need(length(resp_var) == 1, "Please define a column for Response variable"))
validate(need(length(x) == 1, "Please define a column for X variable"))
validate(need(is.factor(ANL[[resp_var]]), "Please select a factor variable as the response."))
validate(need(is.factor(ANL[[x]]), "Please select a factor variable as the X-Variable."))
teal::validate_has_data(ANL, 10)
Expand All @@ -285,8 +296,6 @@ srv_g_response <- function(id,
rotate_xaxis_labels <- input$rotate_xaxis_labels
ggtheme <- input$ggtheme

validate(need(!is.null(ggtheme), "Please select a theme."))

arg_position <- if (freq) "stack" else "fill" # nolint

rowf <- if (length(row_facet_name) == 0) NULL else as.name(row_facet_name) # nolint
Expand Down
45 changes: 34 additions & 11 deletions R/tm_g_scatterplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,38 @@ srv_g_scatterplot <- function(id,
data_extract <- list(
x = x, y = y, color_by = color_by, size_by = size_by, row_facet = row_facet, col_facet = col_facet
)
selector_list <- teal.transform::data_extract_multiple_srv(data_extract, data)
selector_list <- teal.transform::data_extract_multiple_srv(
data_extract = data_extract,
datasets = data,
select_validation_rule = list(
x = ~ if (length(.) != 1) "Please select exactly one x var.",
y = ~ if (length(.) != 1) "Please select exactly one y var.",
color_by = ~ if (length(.) > 1) "There must be 1 or no color variable.",
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved
size_by = ~ if (length(.) > 1) "There must be 1 or no size variable.",
row_facet = shinyvalidate::compose_rules(
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved
~ if (length(.) > 1) "There must be 1 or no column facetting variable.",
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
~ if (length(.) == 1 &&
length(selector_list()$col_facet()$select) == 1 &&
(.) == selector_list()$col_facet()$select) {
"Row and column facetting variables must be different."
}
),
col_facet = shinyvalidate::compose_rules(
~ if (length(.) > 1) "There must be 1 or no row facetting variable.",
~ if (length(.) == 1 &&
length(selector_list()$row_facet()$select) == 1 &&
(.) == selector_list()$row_facet()$select) {
"Row and column facetting variables must be different."
}
)
)
)

iv_r <- reactive({
iv <- shinyvalidate::InputValidator$new()
iv$add_rule("ggtheme", shinyvalidate::sv_required("Please select a theme"))
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
teal.transform::compose_and_enable_validators(iv, selector_list)
})

anl_merged_input <- teal.transform::merge_expression_srv(
selector_list = selector_list,
Expand Down Expand Up @@ -462,6 +493,8 @@ srv_g_scatterplot <- function(id,
)

output_q <- reactive({
teal::validate_inputs(iv_r())

ANL <- merged$anl_q_r()[["ANL"]] # nolint

x_var <- as.vector(merged$anl_input_r()$columns_source$x)
Expand Down Expand Up @@ -492,16 +525,6 @@ srv_g_scatterplot <- function(id,
log_x <- input$log_x
log_y <- input$log_y

validate(need(!is.null(ggtheme), "Please select a theme."))
validate(need(length(x_var) == 1, "There must be exactly one x var."))
validate(need(length(y_var) == 1, "There must be exactly one y var."))
validate(need(is.null(color_by_var) || length(color_by_var) <= 1, "There must be 1 or no color variable."))
validate(need(is.null(size_by_var) || length(size_by_var) <= 1, "There must be 1 or no size variable."))
validate(need(length(row_facet_name) <= 1, "There must be 1 or no row facetting variable."))
validate(need(length(col_facet_name) <= 1, "There must be 1 or no column facetting variable."))
if (length(row_facet_name) * length(col_facet_name) > 0) {
validate(need(row_facet_name != col_facet_name, "Row and column facetting variables must be different."))
}
validate(need(
length(row_facet_name) == 0 || inherits(ANL[[row_facet_name]], c("character", "factor", "Date", "integer")),
"`Row facetting` variable must be of class `character`, `factor`, `Date`, or `integer`"
Expand Down
13 changes: 11 additions & 2 deletions R/tm_g_scatterplotmatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,17 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab
moduleServer(id, function(input, output, session) {
selector_list <- teal.transform::data_extract_multiple_srv(
data_extract = list(variables = variables),
datasets = data
datasets = data,
mhallal1 marked this conversation as resolved.
Show resolved Hide resolved
select_validation_rule = list(
variables = ~ if (length(.) <= 1) "Please select at least 2 columns."
)
)

iv_r <- reactive({
iv <- shinyvalidate::InputValidator$new()
teal.transform::compose_and_enable_validators(iv, selector_list)
})

anl_merged_input <- teal.transform::merge_expression_srv(
datasets = data,
join_keys = get_join_keys(data),
Expand All @@ -188,6 +196,8 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab

# plot
output_q <- reactive({
teal::validate_inputs(iv_r())

qenv <- merged$anl_q_r()
ANL <- qenv[["ANL"]] # nolint

Expand All @@ -204,7 +214,6 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab
"na.fail"
}

validate(need(length(cols_names) > 1, "Need at least 2 columns."))
teal::validate_has_data(ANL, 10)
teal::validate_has_data(ANL[, cols_names], 10, complete = TRUE, allow_inf = FALSE)

Expand Down
Loading