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

Date and DateTime invalid ranges crashes app #158

Closed
nikolas-burkoff opened this issue Jan 13, 2023 · 3 comments
Closed

Date and DateTime invalid ranges crashes app #158

nikolas-burkoff opened this issue Jan 13, 2023 · 3 comments
Assignees
Labels
bug Something isn't working core

Comments

@nikolas-burkoff
Copy link
Contributor

nikolas-burkoff commented Jan 13, 2023

From #155 (review)

Change date or date time so that the "from" is after "to":

image

And the app crashes:

image

image

library(teal)
library(scda)

adsl <- synthetic_cdisc_dataset("latest", "adsl")

app <- init(
  data = teal_data(dataset("ADSL", adsl)),
  modules = example_module()
)

runApp(app)

This should be fixed alongside #133 when there is a "save" button to enable validation of filter panel inputs.

Please also add tests

@nikolas-burkoff
Copy link
Contributor Author

See #133 (comment) for example shinyvalidate with these widgets

@donyunardi
Copy link
Contributor

donyunardi commented Feb 3, 2023

Should we consider changing the airDatepickerInput to dateRangeInput?

div(
class = "flex w-80 filter_datelike_input",
div(class = "w-45 text-center", {
x <- shinyWidgets::airDatepickerInput(
inputId = ns("selection_start"),
value = self$get_selected()[1],
startView = self$get_selected()[1],
timepicker = TRUE,
minDate = private$choices[1],
maxDate = private$choices[2],
update_on = "close",
addon = "none",
position = "bottom right"
)
x$children[[2]]$attribs <- c(x$children[[2]]$attribs, list(class = "input-sm"))
x
}),
span(
class = "input-group-addon w-10",
span(class = "input-group-text w-100 justify-content-center", "to"),
title = "Times are displayed in the local timezone and are converted to UTC in the analysis"
),
div(class = "w-45 text-center", {
x <- shinyWidgets::airDatepickerInput(
inputId = ns("selection_end"),
value = self$get_selected()[2],
startView = self$get_selected()[2],
timepicker = TRUE,
minDate = private$choices[1],
maxDate = private$choices[2],
update_on = "close",
addon = "none",
position = "bottom right"
)
x$children[[2]]$attribs <- c(x$children[[2]]$attribs, list(class = "input-sm"))
x
})
),

Here's an example where user has to pick an end date greater than start date.
This way, we don't need to add any validation to check the date ranges.

This could be along the line when @asbates mentioned about observeEvent today.

library(shiny)
ui <- fluidPage(
  dateRangeInput("date_range", "Input date range", start = "2001-01-01", end = "2001-02-01")
)

server <- function(input, output, session) {
    observeEvent(input$date_range[1], {
        end_date = input$date_range[2]
        if (input$date_range[2] < input$date_range[1]) {
            end_date = input$date_range[1]
        }        
        updateDateRangeInput(session, "date_range",
        label = "Date range",
        start = input$date_range[1],
        end = end_date,
        min = input$date_range[1]
        )
    })
}

shinyApp(ui, server)

@donyunardi
Copy link
Contributor

Acceptance Criteria:

  • Create a flow to prevent user to pick a start date < end date

@BLAZEWIM BLAZEWIM self-assigned this Feb 15, 2023
BLAZEWIM added a commit that referenced this issue Feb 21, 2023
# Pull Request

Fixes
#[158](#158)


1. At initialization, when values are not valid, corrections will be
performed with warnings.
2. Later, when changed by the user, shinyvalidate is used.
 
Example to test:

```
adsl <- synthetic_cdisc_dataset("latest", "adsl")

app <- init(
  data = teal_data(dataset("ADSL", adsl)),
  modules = example_module(),
  filter = list(
    "ADSL" = list(
      RANDDT = list(selected = c("2021-02-16", "2021-02-17")),
      TRT01SDTM = list(selected = c("2021-02-11 17:09:18", "2021-02-10 20:42:27"))
    )
  )
)
runApp(app)
```

---------

Signed-off-by: Marek Blazewicz <110387997+BLAZEWIM@users.noreply.github.com>
Co-authored-by: Dawid Kałędkowski <6959016+gogonzo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core
Projects
None yet
Development

No branches or pull requests

4 participants