Add picks to tm_g_butterfly module#335
Conversation
|
✅ All contributors have signed the CLA |
|
I have read the CLA Document and I hereby sign the CLA |
Code Coverage SummaryDiff against mainResults for commit: b9db744 Minimum allowed coverage is ♻️ This comment has been updated with latest results |
Unit Test Performance Difference
Additional test case details
Results for commit e7056d7 ♻️ This comment has been updated with latest results. |
|
I added the following changes:
I tested the example app manually and I observe no issue in the behavior. The CI fails but is due other modules, not due to code changed in this PR. |
| shiny::validate( | ||
| shiny::need(length(right_var_name) > 0, "Right Dichotomization Variable is required."), | ||
| shiny::need(length(left_var_name) > 0, "Left Dichotomization Variable is required."), | ||
| shiny::need(length(category_var_name) > 0, "Category Variable is required."), | ||
| shiny::need( | ||
| is.factor(ANL[[right_var_name]]), | ||
| "Right Dichotomization Variable must be a factor variable, contact developer." | ||
| ), | ||
| shiny::need( | ||
| is.factor(ANL[[left_var_name]]), | ||
| "Left Dichotomization Variable must be a factor variable, contact developer." |
There was a problem hiding this comment.
Do you see a problem that it is using shiny::validate instead of teal::validate_input?
llrs-roche
left a comment
There was a problem hiding this comment.
Great work.
I was a bit surprised when running the app and I saw some input elements weren't using picks for selecting values. The "Choose Up To 2:" can be done with an teal::validate_input(), not sure how it has been done on tmc or other packages.
Very few comments about the code itself. I'd like to have more tests but that is out of the scope for now.
| #' selected = "AETOXGR", | ||
| #' choices = c("AETOXGR", "None") | ||
| #' color_by_var = variables( | ||
| #' choices = c("AETOXGR", "None"), |
There was a problem hiding this comment.
Should None be replaced by allowing no selection? I don't think None is a valid variable on that environment and this doesn't allow to disable the colors.
There was a problem hiding this comment.
Yes, good observation. I changed to allow no color in the plot and updated the example
| color_by_var <- migrate_choices_selected_to_variables(color_by_var, multiple = FALSE) | ||
| filter_var <- migrate_choices_selected_to_variables(filter_var, null.ok = TRUE) | ||
| facet_var <- migrate_choices_selected_to_variables(facet_var, null.ok = TRUE) | ||
| count_by_var <- migrate_choices_selected_to_values(count_by_var) |
There was a problem hiding this comment.
This function returns a pick of class values.
There was a problem hiding this comment.
Yes, but I think it is the correct class of the object. It is a pick class of values because it is not connected to datasets or variables, the choices are independent of the dataset.
| if (teal.picks::is_pick_multiple(right_var$variables)) { | ||
| warning( | ||
| "`right_var` accepts only a single variable selection. ", | ||
| "Forcing `teal.picks::variables(multiple)` to FALSE." | ||
| ) | ||
| attr(right_var$variables, "multiple") <- FALSE | ||
| } |
There was a problem hiding this comment.
I think this is also a good candidate for a helper function. Note that is repeated 4 times in only this module. Something like
as_pick_single <- function(var, name) {
if (teal.picks::is_pick_multiple(right_var$variables)) {
warning(
sprintf("`%s` accepts only a single variable selection. ", name)
"Forcing `teal.picks::variables(multiple)` to FALSE."
)
attr(var "multiple") <- FALSE
var
}That could be used as right_var$variables <- as_pick_single(right_var$variables, "right_var")
| facet_var_name <- merged$variables()$facet_var | ||
|
|
||
| teal::validate_inputs(iv()) | ||
| teal::validate_has_data(ANL, min_nrow = 0, msg = "ANL Data is empty") |
There was a problem hiding this comment.
I guess here we are mimicking previous checks. But, wouldn't it make sense to add min_nrow = 10 or some other value? This might be a case of leave the code better than what we found.
There was a problem hiding this comment.
I agree with you, but I suggest 1 as minimum for filtering with big constraints
| }), | ||
| id = ANL$USUBJID, | ||
| facet_rows = .(if (!is.null(facet_var_name)) { | ||
| bquote(ANL[[.(facet_var_name)]]) |
There was a problem hiding this comment.
Are those many bquotes needed? Then it might be worth to consider using within
| bquote(ANL[[.(facet_var_name)]]) | |
| ANL[[.(facet_var_name)]] |
There was a problem hiding this comment.
Yes, I changed everything to within so it is more readable
|
Hi, many thanks for your suggestions. I tried to apply all of them. Regarding |
It solves part of #330
Following similar strategy to #331 we are only having one picks srv and ui function and converting
choices_selectedto picks. However, there is a bug under investigation on teal.picks and currently the example crashes if we change the value of any variable on the default method.Please try this example to test the app