Skip to content

Fix issues related to set_props() in WebSocket callbacks#3759

Merged
T4rk1n merged 11 commits into
plotly:websocket-callbacksfrom
CNFeffery:websocket-callbacks
Apr 30, 2026
Merged

Fix issues related to set_props() in WebSocket callbacks#3759
T4rk1n merged 11 commits into
plotly:websocket-callbacksfrom
CNFeffery:websocket-callbacks

Conversation

@CNFeffery

@CNFeffery CNFeffery commented Apr 26, 2026

Copy link
Copy Markdown
Contributor
@CNFeffery

Copy link
Copy Markdown
Contributor Author

Based on the functional demonstration results of the local development version Dash, simulate the streaming content output effect similar to large language models:

demo

Core callback function code:

@app.callback(
    Input("load-stream-content", "nClicks"),
    websocket=True,
    running=[[Output("load-stream-content", "loading"), True, False]],
)
async def load_stream_content(nClicks):

    for s in test_markdown:
        await asyncio.sleep(0.02)

        p = Patch()
        p += s

        set_props("markdown-content", {"markdownStr": p})
@CNFeffery CNFeffery changed the title Fix the issue where Patch objects cannot be updated via set_props() in WebSocket callbacks Apr 27, 2026
Comment thread dash/_callback_context.py Outdated
Comment on lines +375 to +376
if isinstance(value, Patch) or hasattr(value, "to_plotly_json"):
value = json.loads(to_json(value))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get the full compatibility, it should to_json without condition, this ensure we can get all the supported prop types.
But then this extra loads might be expansive when serializing big object. Maybe instead of _send_json we have _send_plotly_json implemented in base that calls a regular _send(value: str).

@T4rk1n T4rk1n left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃

@T4rk1n T4rk1n merged commit a8fbd57 into plotly:websocket-callbacks Apr 30, 2026
70 of 74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants