From 2b4ed30221e0071c73e6b128b4ce1b3a538c8982 Mon Sep 17 00:00:00 2001 From: elp Date: Sun, 26 Jun 2022 16:18:12 -0700 Subject: [PATCH] wip: Use stock bokeh plugin in wasm example #14 --- py/wasm/examples/example_bokeh.html | 6 ++-- py/wasm/examples/example_bokeh.py | 2 +- py/wasm/examples/example_bokeh_plugin.py | 41 ------------------------ py/wasm/examples/example_entrypoint.html | 2 +- 4 files changed, 4 insertions(+), 47 deletions(-) delete mode 100644 py/wasm/examples/example_bokeh_plugin.py diff --git a/py/wasm/examples/example_bokeh.html b/py/wasm/examples/example_bokeh.html index 2b8836d4..e7dd6871 100644 --- a/py/wasm/examples/example_bokeh.html +++ b/py/wasm/examples/example_bokeh.html @@ -52,14 +52,12 @@ # Additional packages to load, if unavailable in the Pyodide repository: # (Can be names of pure Python packages in PyPI, or paths to wheel files.) # - # bundles: - # - altair - # - path/to/my/awesome_package-0.42.0-py3-none-any.whl + bundles: + - h2o-nitro-bokeh # # Additional Python modules or files to copy into the Wasm virtual filesystem: # files: - - example_bokeh_plugin.py - example_bokeh_util.py # # The main Python module to load and execute: diff --git a/py/wasm/examples/example_bokeh.py b/py/wasm/examples/example_bokeh.py index 1c44c64d..f50c7c2d 100644 --- a/py/wasm/examples/example_bokeh.py +++ b/py/wasm/examples/example_bokeh.py @@ -1,5 +1,5 @@ from h2o_nitro import AsyncView as View -from example_bokeh_plugin import bokeh_plugin, bokeh_box +from h2o_nitro_bokeh import bokeh_plugin, bokeh_box from example_bokeh_util import * diff --git a/py/wasm/examples/example_bokeh_plugin.py b/py/wasm/examples/example_bokeh_plugin.py deleted file mode 100644 index 52c2a242..00000000 --- a/py/wasm/examples/example_bokeh_plugin.py +++ /dev/null @@ -1,41 +0,0 @@ -import json -from bokeh.util.version import __version__ as bokeh_version -from bokeh.model import Model -from bokeh.embed import json_item - -from h2o_nitro import box, Box, Plugin, Script - -# Javascript function for embedding the Bokeh plot. -# See: http://docs.bokeh.org/en/latest/docs/user_guide/embed.html#json-items -# Here, we export one function called embed(), which we can later invoke from our Python box(). -_bokeh_embed_js = ''' -exports.embed = (context, element, data) => { - Bokeh.embed.embed_item(JSON.parse(data.model), element.id); -}; -''' - - -def bokeh_plugin(): - """ - Creates a Nitro plugin for the currently installed version of Bokeh. - :return: A plugin - """ - return Plugin( - name='bokeh', - scripts=[ - # Install the Bokeh library. - Script(source=f'https://cdnjs.cloudflare.com/ajax/libs/bokeh/{bokeh_version}/bokeh.min.js'), - # Install our custom Bokeh-embedding Javascript. - Script(source=_bokeh_embed_js, type='inline'), - ], - ) - - -def bokeh_box(model: Model) -> Box: - """ - Creates a Nitro box from a Bokeh model. - :param model: A Bokeh model (plots, widgets, etc.) - :return: A box - """ - # Render the box using our custom embed() function defined in the "bokeh" plugin. - return box(mode='plugin:bokeh.embed', data=dict(model=json.dumps(json_item(model))), ignore=True) \ No newline at end of file diff --git a/py/wasm/examples/example_entrypoint.html b/py/wasm/examples/example_entrypoint.html index f6faf7d6..f35b6eca 100644 --- a/py/wasm/examples/example_entrypoint.html +++ b/py/wasm/examples/example_entrypoint.html @@ -53,7 +53,7 @@ # # bundles: # - altair - # - path/to/my/awesome_package-0.42.0-py3-none-any.whl + # - "path/to/my/awesome_package-0.42.0-py3-none-any.whl" # # Additional Python modules or files to copy into the Wasm virtual filesystem: #