selectbox(
    label: str, 
    options: List[str], 
    default: Optional[str] = None, 
    size: float = 1.0
) -> str

The selectbox function creates a dropdown menu in your app, allowing users to select an option from a predefined list. This is ideal for scenarios where users need to choose from multiple options.

Parameters

  • label (str): The label displayed above the dropdown, describing its purpose.
  • options (list): A list of options that users can select from.
  • default (str): (Optional) The default option. Must be one of the options provided.
  • size (float): (Optional) The width of the component in a row. Defaults to 1.0 (full row). See the Layout Guide for details.

Returns

  • str containing the current value.

Usage Example

Here’s how to use the selectbox function:

from preswald import selectbox

# Create a dropdown menu to select a dataset
choice = selectbox(
    label="Choose Dataset",
    options=["Dataset A", "Dataset B", "Dataset C"]
)

# Use the selected option
print(f"User selected: {choice}")

Key Features

  1. Customizable Options: Pass a list of options to tailor the dropdown to your needs.
  2. Descriptive Labels: Provide clear labels to guide users in making their selection.
  3. Dynamic Outputs: Capture the selected value and use it dynamically within your app.

Example Use Case

Suppose you’re building a data visualization app:

  • Use a selectbox to let users choose a dataset to analyze or visualize.
  • Depending on the selection, display different charts or tables.

Why Use selectbox?

  • Simplicity: A dropdown menu is intuitive and familiar for users.
  • Flexibility: It handles a wide range of options without cluttering the interface.
  • Interactivity: The selected option can drive other app functionality.

Streamline user choices with the selectbox! 🎛️

Was this page helpful?