|
23 | 23 | </py-env>
|
24 | 24 | <h1>Panel Example</h1>
|
25 | 25 | <div id="myplot"></div>
|
26 |
| - <py-script> |
| 26 | +<py-script> |
27 | 27 | import asyncio
|
28 |
| -import json |
29 | 28 | import micropip
|
30 | 29 | import pyodide
|
31 | 30 |
|
32 |
| -from js import Bokeh, console, JSON |
33 |
| - |
34 |
| -from bokeh import __version__ |
35 |
| -from bokeh.document import Document |
36 |
| -from bokeh.embed.util import OutputDocumentFor, standalone_docs_json |
37 |
| -from bokeh.protocol.messages.patch_doc import process_document_events |
38 |
| - |
39 |
| -await micropip.install(['panel==0.13.0rc5']) |
| 31 | +await micropip.install(['panel==0.13.0rc8']) |
40 | 32 |
|
41 | 33 | import panel as pn
|
42
10000
| 34 |
|
| 35 | +slider = pn.widgets.FloatSlider(start=0, end=10, name='Amplitude') |
| 36 | + |
43 | 37 | def callback(new):
|
44 | 38 | return f'Amplitude is: {new}'
|
45 | 39 |
|
46 |
| -slider = pn.widgets.FloatSlider(start=0, end=10, name='Amplitude') |
47 |
| - |
48 | 40 | row = pn.Row(slider, pn.bind(callback, slider))
|
49 | 41 |
|
50 |
| -print("about to embed") |
51 |
| - |
52 |
| -def doc_json(model, target): |
53 |
| - doc = model.server_doc() |
54 |
| - model = doc.roots[0] |
55 |
| - docs_json = standalone_docs_json([model]) |
56 |
| - |
57 |
| - doc_json = list(docs_json.values())[0] |
58 |
| - root_id = doc_json['roots']['root_ids'][0] |
59 |
| - |
60 |
| - return doc, json.dumps(dict( |
61 |
| - target_id = target, |
62 |
| - root_id = root_id, |
63 |
| - doc = doc_json, |
64 |
| - version = __version__, |
65 |
| - )) |
66 |
| - |
67 |
| -def link_docs(pydoc, jsdoc): |
68 |
| - def jssync(event): |
69 |
| - if (event.setter_id is not None): |
70 |
| - return |
71 |
| - events = [event] |
72 |
| - json_patch = jsdoc.create_json_patch_string(pyodide.to_js(events)) |
73 |
| - pydoc.apply_json_patch(json.loads(json_patch)) |
74 |
| - |
75 |
| - jsdoc.on_change(pyodide.create_proxy(jssync), pyodide.to_js(False)) |
76 |
| - |
77 |
| - def pysync(event): |
78 |
| - json_patch = process_document_events([event], use_buffers=False)[0] |
79 |
| - |
80 |
| - jsdoc.apply_json_patch(JSON.parse(json_patch), {}, setter_id='js') |
81 |
| - |
82 |
| - pydoc.on_change(pysync) |
83 |
| - |
84 |
| -async def show(plot, target): |
85 |
| - pydoc, model_json = doc_json(plot, target) |
86 |
| - views = await Bokeh.embed.embed_item(JSON.parse(model_json)) |
87 |
| - print("Done embedding...") |
88 |
| - jsdoc = views[0].model.document |
89 |
| - link_docs(pydoc, jsdoc) |
| 42 | +await pn.io.pyodide.show(row, 'myplot') |
| 43 | +</py-script> |
90 | 44 |
|
91 |
| -await show(row, 'myplot') |
92 |
| - </py-script> |
93 | 45 | </body>
|
94 | 46 | </html>
|
0 commit comments