Is there a way to generate the custom tool’s code using JavaScript instead of TypeScript
Just use bokeh.util.compiler.JavaScript instead of bokeh.util.compiler.TypeScript.
whether that would obviate the need for compilation?
Alas, the compilation is still required in that case.
How do I pre-build the tool such that it could be loaded without the need for compilation on the remote copmuter?
It’s not a very straightforward process, but it’s possible:
- Run the example as is
- Open the saved file and find the
<script> tag in <head> that contains all the compiled code. In the case of the custom tool it will contain "custom/draw_tool": function ...
- In the original example code, remove
TS_CODE and __implementation__ completely
- Create a custom template:
from bokeh.core.templates import get_env
template = get_env().from_string("""
{% extends "file.html" %}
{% block postamble %}
[...]
{% endblock %}
- Replace the
[...] line with the <script> tag you found earlier, including the tag itself
- Now, we need to use the custom template but
show doesn’t support it - we will have to use save from bokeh.io:
save(plot, template=template)
save works just like show but it doesn’t open the browser window - you and the users of the resulting Python script will have to open the generated HTML file by hand or by writing some code that just opens the HTML file in a browser.