slider(label: str, min_val: int, max_val: int, step: int, default: int)

The slider function adds an interactive slider to your app, enabling users to input numerical values within a specified range. This is especially useful for dynamic controls, such as selecting a range or adjusting parameters.

Parameters

  • label (str): The label displayed next to the slider, indicating its purpose.
  • min_val (int): The minimum value the slider can take.
  • max_val (int): The maximum value the slider can take.
  • step (int): The step size between values on the slider.
  • default (int): The initial/default value of the slider.
  • size (float): (Optional) The width of the component in a row. Defaults to 1.0 (full row). See the Layout Guide for details.

Usage Example

Here’s an example of how to add a slider to your app:

from preswald import slider

# Create a slider for selecting the number of rows to display
value = slider(
    label="Rows to Display",
    min_val=1,
    max_val=100,
    step=10,
    default=20
)

# Use the selected value
print(f"Slider selected value: {value}")

Key Features

  1. Customizable Range: Define the range of values with min_val and max_val.
  2. Adjustable Precision: Control increments using the step parameter.
  3. Default Selection: Set a sensible starting point with the default parameter.
  4. Real-Time Input: Values update dynamically as the user interacts with the slider.

Why Use slider?

Sliders provide an intuitive way to capture numerical input, enhancing user experience by making the interface interactive and responsive.

Simplify user input with the slider! 🛠️