11{
22 "cells" : [
3+ {
4+ "cell_type" : " markdown" ,
5+ "metadata" : {},
6+ "source" : [
7+ " # Output Widget append_display_data Test\n " ,
8+ " \n " ,
9+ " This notebook tests the functionality of `append_display_data()` on Output widgets.\n " ,
10+ " The issue described in [#16739](https://github.com/microsoft/vscode-jupyter/issues/16739) is that content added asynchronously via `append_display_data()` doesn't appear in VS Code."
11+ ]
12+ },
313 {
414 "cell_type" : " code" ,
515 "execution_count" : null ,
616 "metadata" : {},
717 "outputs" : [],
818 "source" : [
919 " import asyncio\n " ,
10- " from IPython.display import display\n " ,
11- " from ipywidgets import HTML, Output\n " ,
12- " \n " ,
13- " outputs = [Output() for _ in range(3)]\n " ,
14- " display(*outputs)\n " ,
15- " \n " ,
16- " async def reproduce_bug():\n " ,
17- " for i in range(3):\n " ,
18- " await asyncio.sleep(0.01)\n " ,
19- " outputs[i].append_display_data(HTML(f\" Content {i}\" ))\n " ,
20+ " from IPython.display import display, HTML\n " ,
21+ " from ipywidgets import Output"
22+ ]
23+ },
24+ {
25+ "cell_type" : " markdown" ,
26+ "metadata" : {},
27+ "source" : [
28+ " ## Test 1: Synchronous append_display_data\n " ,
2029 " \n " ,
21- " asyncio.create_task(reproduce_bug()) "
30+ " According to @DonJayamanne's comment, even synchronous calls don't work. "
2231 ]
2332 },
2433 {
2736 "metadata" : {},
2837 "outputs" : [],
2938 "source" : [
30- " # Test synchronous append_display_data (per comment from DonJayamanne) \n " ,
39+ " # Create output widgets \n " ,
3140 " sync_outputs = [Output() for _ in range(2)]\n " ,
3241 " display(*sync_outputs)"
3342 ]
3847 "metadata" : {},
3948 "outputs" : [],
4049 "source" : [
41- " sync_outputs[0].append_display_data(HTML(\" Sync Content 0\" ))\n " ,
42- " sync_outputs[1].append_display_data(HTML(\" Sync Content 1\" ))"
50+ " # Append content synchronously\n " ,
51+ " sync_outputs[0].append_display_data(HTML(\" <div style='color: green; font-weight: bold;'>✅ Sync Content 0 - This should appear!</div>\" ))\n " ,
52+ " sync_outputs[1].append_display_data(HTML(\" <div style='color: blue; font-weight: bold;'>✅ Sync Content 1 - This should appear!</div>\" ))"
53+ ]
54+ },
55+ {
56+ "cell_type" : " markdown" ,
57+ "metadata" : {},
58+ "source" : [
59+ " ## Test 2: Asynchronous append_display_data\n " ,
60+ " \n " ,
61+ " This was the original issue - async content doesn't appear."
62+ ]
63+ },
64+ {
65+ "cell_type" : " code" ,
66+ "execution_count" : null ,
67+ "metadata" : {},
68+ "outputs" : [],
69+ "source" : [
70+ " # Create output widgets for async test\n " ,
71+ " async_outputs = [Output() for _ in range(3)]\n " ,
72+ " display(*async_outputs)\n " ,
73+ " \n " ,
74+ " async def append_async_content():\n " ,
75+ " for i in range(3):\n " ,
76+ " await asyncio.sleep(0.1) # Small delay\n " ,
77+ " color = ['red', 'orange', 'purple'][i]\n " ,
78+ " async_outputs[i].append_display_data(\n " ,
79+ " HTML(f\" <div style='color: {color}; font-weight: bold;'>✅ Async Content {i} - This should appear!</div>\" )\n " ,
80+ " )\n " ,
81+ " \n " ,
82+ " # Start the async task\n " ,
83+ " asyncio.create_task(append_async_content())"
84+ ]
85+ },
86+ {
87+ "cell_type" : " markdown" ,
88+ "metadata" : {},
89+ "source" : [
90+ " ## Test 3: Mixed content types\n " ,
91+ " \n " ,
92+ " Test with different content types (HTML, text, etc.)"
93+ ]
94+ },
95+ {
96+ "cell_type" : " code" ,
97+ "execution_count" : null ,
98+ "metadata" : {},
99+ "outputs" : [],
100+ "source" : [
101+ " # Create output widget for mixed content\n " ,
102+ " mixed_output = Output()\n " ,
103+ " display(mixed_output)\n " ,
104+ " \n " ,
105+ " # Add different types of content\n " ,
106+ " mixed_output.append_display_data(HTML(\" <h3>HTML Content</h3>\" ))\n " ,
107+ " mixed_output.append_display_data({\" text/plain\" : \" Plain text content\" })\n " ,
108+ " mixed_output.append_display_data(HTML(\" <p style='color: green;'>More HTML content</p>\" ))"
109+ ]
110+ },
111+ {
112+ "cell_type" : " markdown" ,
113+ "metadata" : {},
114+ "source" : [
115+ " ## Expected Results\n " ,
116+ " \n " ,
117+ " - **Before fix**: Content doesn't appear in Output widgets, console shows \" Model not found in Kernel state to render output\" errors\n " ,
118+ " - **After fix**: All content should appear properly in the respective Output widgets\n " ,
119+ " \n " ,
120+ " If you see the colored text content in the Output widgets above, the fix is working!"
43121 ]
44122 }
45123 ],
46124 "metadata" : {
47- "language_info" : {
48- "name" : " python"
125+ "kernelspec" : {
126+ "display_name" : " Python 3" ,
127+ "language" : " python" ,
128+ "name" : " python3"
49129 },
50- "orig_nbformat" : 4
130+ "language_info" : {
131+ "codemirror_mode" : {
132+ "name" : " ipython" ,
133+ "version" : 3
134+ },
135+ "file_extension" : " .py" ,
136+ "mimetype" : " text/x-python" ,
137+ "name" : " python" ,
138+ "nbconvert_exporter" : " python" ,
139+ "pygments_lexer" : " ipython3" ,
140+ "version" : " 3.8.0"
141+ }
51142 },
52143 "nbformat" : 4 ,
53- "nbformat_minor" : 2
144+ "nbformat_minor" : 4
54145}
0 commit comments