Adds validate_input() -- previously named as "picks"#1642
Conversation
- teal_transform_module to not use badge_dropdown
Code Coverage SummaryDiff against mainResults for commit: 830613b Minimum allowed coverage is ♻️ This comment has been updated with latest results |
Unit Tests Summary 1 files 36 suites 4m 40s ⏱️ Results for commit 830613b. ♻️ This comment has been updated with latest results. |
Unit Test Performance Difference
Additional test case details
Results for commit 1d5804a ♻️ This comment has been updated with latest results. |
|
8 failed tests in R CMD CHECK Error in `testthat::test_that("e2e: validate_input validates dateRangeInput")`: argument "code" is missing, with no defaultdoes |
|
Ah ok, those are those 8 tests that do not have any body yet |
Yup, this is for the first volunteer |
averissimo
left a comment
There was a problem hiding this comment.
Looks good! I've added missing tests with shinytest2
Pending CI run, but this feature has been heavily tested with tmg and tmc development
validate_input() -- previously named as "picks"
# Pull Request
<!--- Replace `#nnn` with your issue link for reference. -->
### Changes description
- [x] Resets message under input when it's changed to prevent outdated
errors
- See screencast on first comment
- [x] ~Allows for multiple validation using `add` parameter _(instead of
1 by 1)_~
- ~Similar implementation to `checkmate::assert_***(..., add =
collection)`~
- Needs alternate solution
- [x] Exports `validate_input` function
- [x] Fixes initialization problem
### Example app with some errors:
- Validate `picks` with non-empty
- Both inputs cannot choose the same letter
```r
#
pkgload::load_all("../teal.picks")
pkgload::load_all("../teal")
data <- within(teal_data(), letters <- data.frame(letter = head(LETTERS)))
picks_letters <- picks(
datasets("letters", "letters"),
variables("letter", "letter"),
values(selected = NULL)
)
my_module <- module(
label = "My Module",
datanames = NULL,
ui = function(id) {
ns <- NS(id)
teal.widgets::standard_layout(
encoding = tagList(
tags$h3("Letters"),
teal.picks::picks_ui(ns("letters"), picks_letters),
tags$h3("Letters2"),
checkboxGroupInput(ns("letters2"), "Select letters:", choices = head(LETTERS), inline = TRUE),
),
output = tagList(
tags$h3("Sample plot"),
plotOutput(ns("plot"))
)
)
},
server = function(id, data) {
moduleServer(id, function(input, output, session) {
selectors <- list(letters = picks_letters)
anl_inputs <- picks_srv(picks = selectors, data = data)
validated_q <- reactive({
validate_input(
"letters-values-selected",
condition = length(anl_inputs$letters()$values$selected) > 0,
message = "Select at least one letter."
)
validate_input(
c("letters-values-selected", "letters2"),
condition = all(!anl_inputs$letters()$values$selected %in% input$letters2),
message = "Letters in the first group should not be in the second group."
)
data()
})
output$plot <- renderPlot({
letters <- validated_q()$letters$letter
tab <- rbind(
Group1 = as.integer(letters %in% anl_inputs$letters()$values$selected),
Group2 = as.integer(letters %in% input$letters2)
)
colnames(tab) <- letters
barplot(
tab,
beside = TRUE, legend.text = TRUE, main = "Selected letters per group",
col = c("steelblue", "tomato")
)
})
})
}
)
init(data = data, modules = my_module) |> shiny::runApp()
```
---------
Signed-off-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
Co-authored-by: Dawid Kaledkowski <dawid.kaledkowski@gmail.com>
…edesign_extraction@main
Closes insightsengineering/NEST-roadmap#36
Check also with:
Introduces
validate_inputas an alternative toshinyvalidatepackage. Function is easier to handle thanshinyvalidate, as one can usevalidate_input()inreactiveand display-validation-error on the input and throw shiny-validate-error in the same time. See tmg PR to see how it works