10000 Simplify panel example · fskydev/pyscript@5f25668 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f25668

Browse files
committed
Simplify panel example
1 parent a597f5c commit 5f25668

File tree

1 file changed

+6
-54
lines changed

1 file changed

+6
-54
lines changed

pyscriptjs/public/panel.html

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,72 +23,24 @@
2323
</py-env>
2424
<h1>Panel Example</h1>
2525
<div id="myplot"></div>
26-
<py-script>
26+
<py-script>
2727
import asyncio
28-
import json
2928
import micropip
3029
import pyodide
3130

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'])
4032

4133
import panel as pn
42 10000 34

35+
slider = pn.widgets.FloatSlider(start=0, end=10, name='Amplitude')
36+
4337
def callback(new):
4438
return f'Amplitude is: {new}'
4539

46-
slider = pn.widgets.FloatSlider(start=0, end=10, name='Amplitude')
47-
4840
row = pn.Row(slider, pn.bind(callback, slider))
4941

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>
9044

91-
await show(row, 'myplot')
92-
</py-script>
9345
</body>
9446
</html>

0 commit comments

Comments
 (0)
0