validate_has_data: Validate that dataset has a minimum number of observations

View source: R/validations.R

validate_has_dataR Documentation

Validate that dataset has a minimum number of observations

Description

[Stable]

Usage

validate_has_data(
  x,
  min_nrow = NULL,
  complete = FALSE,
  allow_inf = TRUE,
  msg = NULL
)

Arguments

x

(data.frame)

min_nrow

(numeric(1)) Minimum allowed number of rows in x.

complete

(logical(1)) Flag specifying whether to check only complete cases. Defaults to FALSE.

allow_inf

(logical(1)) Flag specifying whether to allow infinite values. Defaults to TRUE.

msg

(character(1)) Additional message to display alongside the default message.

Details

This function is a wrapper for shiny::validate.

Examples

library(teal)
ui <- fluidPage(
  sliderInput("len", "Max Length of Sepal",
    min = 4.3, max = 7.9, value = 5
  ),
  plotOutput("plot")
)

server <- function(input, output) {
  output$plot <- renderPlot({
    iris_df <- iris[iris$Sepal.Length <= input$len, ]
    validate_has_data(
      iris_df,
      min_nrow = 10,
      complete = FALSE,
      msg = "Please adjust Max Length of Sepal"
    )

    hist(iris_df$Sepal.Length, breaks = 5)
  })
}
if (interactive()) {
  shinyApp(ui, server)
}


teal documentation built on May 29, 2024, 10:11 a.m.