-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
shinyvalidate
improvements
#786
Conversation
Code Coverage Summary
Diff against main
Results for commit: 37fc943 Minimum allowed coverage is ♻️ This comment has been updated with latest results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
As we're using
shinyvalidate
in the examples we need to add it to SUGGESTS in the DESC file -
I'm not sure about the name of the function - as we are not just gathering any validation failures but also calling shiny::validate as well - not sure what to call it instead though but making it clear there's "validation" going on in the function is probably a good idea?
-
I wonder if there's a way to use S3 dispatching here so that users of these functions only need to know one rather than having to look up which of the three they need to use in their case?
-
I don't think there's any case where we want to call these functions but not call shiny::validate (i.e. just get the messages and then do something with them) - the reason I ask is by coupling the gathering to the validation we can't get the messages out if we need them. We could decouple completely and only have the gathering messages here and let the module developer add the shiny::validate themselves?
I thought about it.
I'm open to suggestions. The name is derived from the original design, where it would only collate messages and put into a
That was the original design, the function would only put messages together and then it would be called with |
Changed to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NEWS.md
Outdated
@@ -1,5 +1,9 @@ | |||
# teal 0.12.0.9011 | |||
|
|||
### New features | |||
|
|||
* Added the `validate_inputs` function that produces informative error messages in app output. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Added the `validate_inputs` function that produces informative error messages in app output. | |
* Added `validate_inputs` and `validate_inputs_segregated` functions that produce informative error messages in app outputs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may also move this below the "Major breaking changes" section but since we're going to tidy up the NEWS before the next release i think it's fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may also move this below the "Major breaking changes" section but since we're going to tidy up the NEWS before the next release i think it's fine
Is it not a "new feature"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is yes - I would move the whole New feature section below the "we have changed how teal modules work after 5 years" breaking change mention. But this can all be done later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
_pkgdown.yml
Outdated
@@ -52,6 +52,7 @@ reference: | |||
- title: Validation functions | |||
contents: | |||
- starts_with("validate_") | |||
- starts_with("gather_fails") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- starts_with("gather_fails") |
As those functions use keywords internal they don't appear in pkgdown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only at the bottom of the file use @keywords internal
, pkgdown breaks if the main ones are not added here (but I did forget to change the name here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup though the line above starts_with("validate_") should cover them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I hear they are to deprecated ("are we still using those?") so maybe it makes sense to add an extra line for these two?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I hear they are to deprecated ("are we still using those?")
They are used quite a bit downstream so I doubt they will be going.. but happy for you to add these extra two explicitly - as long as pkgdown doesn't then output them twice :)
R/validate_inputs.R
Outdated
#' into one message passed to `validate`. | ||
#' | ||
#' `shiny::validate` is used to withhold rendering of an output element until | ||
#' certain conditions are met and a print a validation message in place |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' certain conditions are met and a print a validation message in place | |
#' certain conditions are met and prints a validation message in place |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are both wrong here. It should read "is used to withhold (...) and (to?) print".
R/validate_inputs.R
Outdated
#' `shinyvalidate::InputValidator` allows to validate input elements | ||
#' and display specific messages in their respective input widgets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' `shinyvalidate::InputValidator` allows to validate input elements | |
#' and display specific messages in their respective input widgets. | |
#' `shinyvalidate::InputValidator` allows the validation of input elements | |
#' and to display specific messages in their respective input widgets. |
R/validate_inputs.R
Outdated
#' @return | ||
#' Returns NULL if the final validation call passes and a `shiny.silent.error` if it fails. | ||
#' | ||
#' @seealso \code{[shinyvalidate::InputValidator]} \code{[shiny::validate]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' @seealso \code{[shinyvalidate::InputValidator]} \code{[shiny::validate]} | |
#' @seealso [`shinyvalidate::InputValidator`], [`shiny::validate`] |
I think we can do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Thank you! I could NOT get the links to work 😠
#' @seealso \code{[shinyvalidate::InputValidator]} \code{[shiny::validate]} | ||
#' | ||
#' @examples | ||
#' library(shiny) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
teal depends on shiny so we don't actually need this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just so the example is self-contained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Copied over from tmc: I can work on this tomorrow if no one else has gotten to it. |
NEWS.md
Outdated
@@ -8,6 +8,9 @@ | |||
|
|||
* Due to deprecation of `chunks` in `teal.code`, the `teal` framework now uses their replacement (`qenv`) instead. The documentation in `teal` has been updated to reflect this and custom modules written with `chunks` should be updated to use `qenv`. | |||
|
|||
### New features | |||
|
|||
* Added the `validate_inputs` and `validate_inputs_segregated` functions that produce informative error messages in app output. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Added the `validate_inputs` and `validate_inputs_segregated` functions that produce informative error messages in app output. | |
* Added the `validate_inputs` and `validate_inputs_segregated` functions that produce informative `shinyvalidate` error messages in the app output. |
@@ -0,0 +1,164 @@ | |||
|
|||
#' send input validation messages to output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' send input validation messages to output | |
#' Send `shinyvalidate` input validation messages to output |
|
||
#' send input validation messages to output | ||
#' | ||
#' Captures messages from \code{InputValidator} objects and collates them |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' Captures messages from \code{InputValidator} objects and collates them | |
#' Captures messages from \code{shinyvalidate::InputValidator} objects and collates them |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be a good idea to link to shinyvalidate
functions as they are external to teal
, what do you think @chlebowa ? Maybe only in the description?
For this we can use the format [shinyvalidate::InputValidator()]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and is there a reason to use \code{}
here? I do see any instance of this usage in teal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I kept prefixes from Description on purpose, they appear in Details.
- Links are in
@seealso
\code{}
is the markdown way to highlight text as code, I'm still not used to Rmarkdown in Rd files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chlebowa \code{}
is the old way of assigning code, we now use ``, hence there is no occurence of \code{}
in `teal`.
Could you please re-open the PR and correct them to conserve the good practice?
#' send input validation messages to output | ||
#' | ||
#' Captures messages from \code{InputValidator} objects and collates them | ||
#' into one message passed to \code{validate}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' into one message passed to \code{validate}. | |
#' into one message passed to \code{shiny::validate}. |
Highlighted how? Validation messages come with a CSS class and |
Maybe something similar to highlighting of inputs: red text and red box. And/or larger font size. The fact that validation messages have a class would make this fairly easy. I'll open another issue and we can address this later. |
Closes [this issue](#185) Following the introduction of `validate_inputs` to `teal` by [#199](insightsengineering/teal#786), this PR: + changes all possible input validations from `validate` calls to `shinyvalidate` input validators + passes all validators to `validate_input` funcitons Signed-off-by: Aleksander Chlebowski <[email protected]> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nikolas Burkoff <[email protected]> Co-authored-by: Dawid Kałędkowski <[email protected]> Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
Related to this issue
Adds the
validate_inputs
functions toteal
so they can be called in modules.