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.

Widget Rows

With Rows you’re able to stack widgets horizontally, in a row. Widgets in a Row will automatically wrap to the next line when there is insufficient space.

from lplots.widgets.row import w_row
from lplots.widgets.select import w_select

option1 = w_select(
  label="Select 1",
  options=[
    "alpha",
    "bravo",
    "charlie"
  ],
)

option2 = w_select(
  label="Select 2",
  options=[
    "alpha",
    "bravo",
    "charlie"
  ],
)

w_row(
  items=[option1, option2]
)