Validate user input shiny for python


Would anyone have any tips or suggestions on how to validate a user input in python for shiny?

For example in this app I would like to provide a user friendly message indicating a number is required. Currently the app returns an ugly error message instead.

In R, I would accomplish this using Shiny Validate



Hi Ian,

Thanks for the reprex, we don't have validation in the python package yet, so what I'd recommend is using reactive ui components and a ui.markdown or ui.HTML error message. This was a popular pattern in R land prior to validate

from shiny import App, reactive, render, ui

app_ui = ui.page_fluid(
    ui.input_text("x", "Type a number"),

def server(input, output, session):
    def x_times_2():
        val = int(input.x()) * 2
        print(f"Running x_times_2(). Result is {val}.")
        return val

    def txt1():
        if input.x().isnumeric():
            return ui.output_text_verbatim("x_times_2")
            return ui.markdown("**Please enter a number**")

app = App(app_ui, server)
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.