Reactive Pages
Reactive pages allow you to dynamically update the form based on user input. This is achieved by defining a page as a function that returns a list of widgets. The function can access the
current state
and modify the page accordingly.
The example below creates a simple rating page that shows a message based on the user's rating.
from abstra.forms import RatingInput, TextOutput, run
def rating_page(state):
page = [RatingInput("How would you rate your experience?", key="rating")]
if state["rating"] is None:
return page # Show only the rating input initially
if state["rating"] < 3:
page.append(TextOutput("We're sorry 😢")) # Add a message for low ratings
return page
# Run the reactive form
run([rating_page])
- Initially,
state["rating"]
isNone
, so the page only displays theRatingInput
widget. - When the user provides a rating, the page is re-evaluated.
- If the rating is less than 3, a message is appended to the page and displayed immediately.