Skip to content

Commit

Permalink
doc: Update example code and include additional .is_valid() usage (#7)
Browse files Browse the repository at this point in the history
* update code to python and include add'l usage step

* chore: Move `.is_valid()` to after basic intro

* edit: Simplify sentence

---------

Co-authored-by: Garrick Aden-Buie <[email protected]>
  • Loading branch information
phobson and gadenbuie authored Jan 8, 2025
1 parent 3706f24 commit 757c7cd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ pip install git+https://github.com/posit-dev/py-shiny-validate.git

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

1. Create an InputValidator object: `iv <- InputValidator`
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()`
3. Turn the validator on: `iv.enable()`

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

Expand Down Expand Up @@ -57,3 +57,12 @@ def server(input, output, session):

app = App(app_ui, server)
```

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

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

0 comments on commit 757c7cd

Please sign in to comment.