posit-dev / posit-dev/py-shiny

ui.input_numeric allows typed values outside of min/max

Open
#953 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-triage
Dominant language
Python
Stars
1.8k
Forks
135
Avg merge
2d 18h
Merged PRs (30d)
21

Description

ui.input_numeric does not currently catch/correct typed values outside of the min/max range (aka min/max range arguments are ineffective for typed user input).

This can be reproduced using the example here:
https://shiny.posit.co/py/api/ui.input_numeric.html
when the user types in 1000, the server responds with 1000, even though the max is set to 100.

The expected functionality can be simulated with the app below. When the users enters an out-of-bounds value, it is imediately replaced with the nearest within-bounds value. With modules, one can build their own control system, though this feels like unintented behavior of the ui.input_numeric function.

Thanks,

from shiny import App, Inputs, Outputs, Session, render, ui, reactive

app_ui = ui.page_fluid(
    ui.output_ui("numeric"),
    ui.output_text_verbatim("value"),
)

def server(input, output, session):
    @output
    @render.ui
    def numeric():
        return ui.input_numeric("obs", "Observations:", 10, min=1, max=100)

    @output
    @render.text
    def value():
        return input.obs()

    @reactive.Effect
    def _():
        if not isinstance(input.obs(), int): #this just keeps an empty box from crashing the app
            return
        if input.obs() > 100 :
            ui.update_numeric("obs", label="Observations:", value=100, min = 1, max = 100)
        if input.obs() < 1 :
            ui.update_numeric("obs", label="Observations:", value=1, min = 1, max = 100)   

app = App(app_ui, server)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ui.input_numeric example at the linked documentation page and reproduce the behavior by entering 1000 when max=100, then try a value below min. Trace the input_numeric and update_numeric entry points to determine where typed values are handled; done means out-of-range input is corrected or rejected consistently while valid and empty values still work.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.