Skip to main content

Input Validation for Shiny apps

Project description

shiny_validate

Overview

This is a python implementation of shinyvalidate, which provides input validation for Shiny for Python applications.

Installation

Install from Pypi with:

pip install shiny_validate

Or, you can install the latest development version from GitHub:

pip install git+https://github.com/posit-dev/py-shiny-validate.git

Basic usage

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

  1. Create an InputValidator object: iv = InputValidator()

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

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

That's all you need to do to get validation messages to show up.

from shiny import App, ui, render, req
from shiny_validate import InputValidator, check

app_ui = ui.page_fluid(
    ui.input_text("name", "Name"),
    ui.input_text("email", "Email"),
    ui.output_text("greeting"),
)


def server(input, output, session):
    iv = InputValidator()

    iv.add_rule("name", check.required())
    iv.add_rule("email", check.required())
    iv.add_rule("email", check.email())
    iv.enable()

    @render.text
    def greeting():
        req(iv.is_valid())
        return f"Nice to meet you, {input.name()} <{input.email()}>!"


app = App(app_ui, server)

You can also use the .is_valid() method to ensure that the inputs are valid before rendering an output:

@render.plot
def plot():
    req(iv.is_valid())
    # Build and return a plot if the inputs are valid

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shiny_validate-0.1.3.tar.gz (34.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shiny_validate-0.1.3-py3-none-any.whl (40.2 kB view details)

Uploaded Python 3

File details

Details for the file shiny_validate-0.1.3.tar.gz.

File metadata

  • Download URL: shiny_validate-0.1.3.tar.gz
  • Upload date:
  • Size: 34.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for shiny_validate-0.1.3.tar.gz
Algorithm Hash digest
SHA256 db3f530e0af99c792fb8fe1b3feb760658ce88ea5a35fbb88b8a23c2403291e8
MD5 70d63cbbc5b2728a7df97eb983d70a92
BLAKE2b-256 3a5f499b52ae5f5ccde146a2718feea2fc11ef3411ecaed58f5cdec1c6cd49f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for shiny_validate-0.1.3.tar.gz:

Publisher: publish.yml on posit-dev/py-shiny-validate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file shiny_validate-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: shiny_validate-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 40.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for shiny_validate-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c66842f9b5e9deab8ba87eb6437cb14bbe470c603550d7055acfd3ec1f5d0f70
MD5 c2dffe1b89606e61717d5a930899c438
BLAKE2b-256 590de022d169e127413cbdb9cfe0b1a8e45a77ba78adc6ea5a3a4c820cdc0b64

See more details on using hashes here.

Provenance

The following attestation bundles were made for shiny_validate-0.1.3-py3-none-any.whl:

Publisher: publish.yml on posit-dev/py-shiny-validate

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page