Set the props for a component not included in the callback outputs. If running in a WebSocket context, props are streamed immediately to the client. Otherwise, props are batched and sent with the callback response.
(component_id: typing.Union[str, dict], props: dict)
| 359 | |
| 360 | |
| 361 | def set_props(component_id: typing.Union[str, dict], props: dict): |
| 362 | """ |
| 363 | Set the props for a component not included in the callback outputs. |
| 364 | |
| 365 | If running in a WebSocket context, props are streamed immediately to the |
| 366 | client. Otherwise, props are batched and sent with the callback response. |
| 367 | """ |
| 368 | ws = _get_from_context("dash_websocket", None) |
| 369 | if ws is not None: |
| 370 | # Stream immediately via WebSocket |
| 371 | _id = stringify_id(component_id) |
| 372 | |
| 373 | async def _send_props(): |
| 374 | for prop_name, value in props.items(): |
| 375 | await ws.set_prop(_id, prop_name, value) |
| 376 | |
| 377 | # If we're in an async context, schedule the coroutine |
| 378 | try: |
| 379 | asyncio.get_running_loop() |
| 380 | asyncio.ensure_future(_send_props()) |
| 381 | except RuntimeError: |
| 382 | # No running event loop - run synchronously |
| 383 | asyncio.run(_send_props()) |
| 384 | else: |
| 385 | # Batch for response (existing behavior) |
| 386 | callback_context.set_props(component_id, props) |
searching dependent graphs…