GithubHelp home page GithubHelp logo

isabella232 / shinyvalidate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rstudio/shinyvalidate

0.0 0.0 0.0 2.29 MB

Input validation package for the Shiny web framework

Home Page: https://rstudio.github.io/shinyvalidate/

License: Other

JavaScript 56.44% R 42.98% CSS 0.58%

shinyvalidate's Introduction

shinyvalidate

CRAN R build status Lifecycle: maturing

Overview

shinyvalidate adds input validation capabilities to Shiny.

Installation

Install the latest CRAN release:

install.packages("shinyvalidate")

Or, you can install the latest development version from GitHub using the remotes package.

remotes::install_github("rstudio/shinyvalidate")

Basic usage

To add validation to your Shiny app, you need to:

  1. Create an InputValidator object: iv <- InputValidator$new()

  2. Add one or more validation rules to the InputValidator: iv$add_rule("title", sv_required())

  3. Turn the validator on: iv$enable()

That's all you need to do to get validation messages to show up. Here is a simple example:

Screencast of empty 'Name' and 'Email' fields showing error messages beneath them, and the user providing valid input that clears the errors

library(shiny)
library(shinyvalidate)

ui <- fluidPage(
  textInput("name", "Name"),
  textInput("email", "Email")
)

server <- function(input, output, session) {
  iv <- InputValidator$new()
  iv$add_rule("name", sv_required())
  iv$add_rule("email", sv_required())
  iv$add_rule("email", sv_email())
  iv$enable()
}

shinyApp(ui, server)

To learn about other features of shinyvalidate, including deferred validation, programmatically accessing validation results, and validating Shiny modules, see Introduction to shinyvalidate.

Input widget compatibility

shinyvalidate should work with all of the inputs that are included in Shiny. It will also work with most custom inputs that follow Bootstrap 3 or 4 conventions. Other types of custom inputs can include their own logic for displaying shinyvalidate error messages; see the article Displaying validation errors to learn more.

Prior art

  • Shiny's built-in validation. The shiny::validate() function fits naturally with Shiny's reactive programming model, but has limited usefulness because it only shows validation feedback in downstream reactive outputs, instead of providing the feedback next to the incorrect input, where users expect it.

  • shinyFeedback by @merlinoa, who graciously provided feedback on the design of shinyvalidate. Compared to shinyFeedback, shinyvalidate aims to have a more concise but less flexible R API; and on the UI side, shinyFeedback displays richer feedback on a hard-coded set of components, while shinyvalidate feedback is minimalist but aims to support a larger set of components and is extensible for custom inputs.

shinyvalidate's People

Contributors

rich-iannone avatar jcheng5 avatar cpsievert avatar schloerke avatar daattali avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.