MCPcopy
hub / github.com/StructuredLabs/preswald / selectbox_demo

Function selectbox_demo

preswald/tutorial/hello.py:176–208  ·  view source on GitHub ↗
(load_data)

Source from the content-addressed store, hash-verified

174# --- SELECTBOX COMPONENT ---
175@workflow.atom(dependencies=["load_data"])
176def selectbox_demo(load_data):
177 df = load_data
178 text("## 5. Adding Interactivity with `selectbox()`")
179 text(
180 "Use the dropdown menu below to select a column from the dataset and visualize its distribution."
181 )
182
183 # Create a selectbox for choosing a column to visualize
184 column_choice = selectbox(
185 label="Choose a column to visualize",
186 options=df.select_dtypes(include=["number"]).columns.tolist(),
187 )
188
189 # Create and display a histogram based on the selected column
190 fig = px.histogram(df, x=column_choice, title=f"Distribution of {column_choice}")
191
192 # Display the plot
193 plotly(fig)
194
195 text(
196 """
197The `selectbox()` component allows users to select from a list of options.
198**Example:**
199```python
200from preswald import selectbox
201choice = selectbox(
202 label="Choose Dataset",
203 options=["Dataset A", "Dataset B", "Dataset C"]
204)
205print(f"User selected: {choice}")
206```
207In this example, selecting a column updates the histogram dynamically! """
208 )
209
210
211# --- SEPARATOR COMPONENT ---

Callers

nothing calls this directly

Calls 3

textFunction · 0.90
selectboxFunction · 0.90
plotlyFunction · 0.90

Tested by

no test coverage detected