Each widget functions as a Python class and can be assigned to a variable. By calling .value on the variable, you can access the actual widget value. For example:

from lplots.widgets.select import w_select

options = w_select(
  label="Select an item from the dropdown",
  options=["alpha", "bravo", "charlie"],
)


print(options.value)
# prints `"alpha", "bravo" or "charlie"` depending on user selection

Widgets are rendered in the order that they are called.

Supported Widget Types

Below is a comprehensive list of supported widget types.

Widget Appearance

Each widget allows you to specify appearance and input discriptions.

select = w_multi_select(
  label="Multiselect Input",
  options=["Alpha", "Bravo", "Charlie"],
  appearance={
    "placeholder": "Placeholder…",
    "detail": "(details)",
    "help_text": "Help text",
    "error_text": "Error text",
    "description": "Hover description",
  }
)

appearance: a dict containing widget appearance attributes:

"placeholder": placeholder value displayed before a set value

"detail": secondary label text displayed after thet label

"help_text": informative text displayed below input

"error_text": error text displayed below input that replaces help_text and sets the input state as errored

"description": longer description text displayed in a hoverable tooltip next to the label

Widgets Reactivity

Widgets are reactive, meaning that they automatically update in response to changes in upstream widgets they depend on. In other words, the downstream data transformation will just run, without you having to click the “Run” button explicitly.

For instance, consider a scenario where you use a file selector widget to load a file. If you have a subsequent dropdown widget designed to display values from a specific column in that file, it will dynamically update its list of options whenever the file in the file selector widget changes. This reactive behavior ensures that the widgets remain synchronized and relevant to the current data context.

Example:

# Data Transformation cell 1
from lplots.widgets.ldata import w_ldata_picker
import pandas as pd

# Select a CSV file using the widget
csv = w_ldata_picker(label="Condition CSV", default="latch:///welcome/deseq2/conditions.csv")
# Data Transformation cell 2

# Read the selected file into a Pandas DataFrame
df = pd.read_csv(csv.value.download())

options = w_select(label="Select the condition of interest:", options=list(df["Condition"]))

Important: To enforce the reactive behavior, observe how csv.value is used in the second data transformation block, rather than in the initial block. This setup is crucial because it allows changes in csv.value to trigger the automatic execution of the subsequent data transformation cell.

Can I access a widget value without triggering a cell rerun?

As mentioned above, you can retrieve a widget value with .value. Calling .value inside a cell also causes that cell to re-run automatically when the user input changes for that widget.

For cells with long-running operations, you might want to access a widget’s value without triggering the cell to rerun. You can do this by calling ._signal.sample() instead of .value. Think of ._signal.sample() as capturing a snapshot of the widget’s value at the exact moment you click the “Run” button.

Examples: The following code cell will automatically rerun whenever the widget value changes:

from lplots.widgets.text import w_text_input
text_input = w_text_input(label="Input")

print(text_input.value)

The following code will only execute when the user presses the “Run” button in the UI:

from lplots.widgets.text import w_text_input
text_input = w_text_input(label="Input")

print(text_input._signal.sample())