`autoload_static()` does not function properly with documents containing templates

I have this piece of code:

from bokeh.embed import autoload_static
from bokeh.resources import CDN

script, tag = autoload_static(curdoc(),CDN,"bokeh_script.js")

with open("bokeh_script.js", "w") as f:
    f.write(script)

html_content = f"""
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Bokeh Plot</title>
</head>
<body>
    {tag}
</body>
</html>
"""

# Save the HTML file or serve it to a web browser
with open("bokeh.html", "w") as f:
    f.write(html_content)

If i add this code to end of exaple app whitch does not contains teplates, for example crossfilter. It genaratets html that works.

But if i use dash example with teplates it reurns this error:

throw new Error(`Error rendering Bokeh model: could not find ${(0,
                l.isString)(n) ? `#${n}` : n} HTML tag`);

autoload_static is ancient, I think I wrote it more than a decade ago. Template options came much later and in fact were not added with autoload_static in mind at all. (Templates were added specifically to support the Bokeh server use-case.) So it does not really surprise me that these two features do not work together, especially since, as far as I can tell, almost no-one ever uses autoload_static [1].

Beyond that, I am not actually sure how templates even could be expected to function with autoload_static. The purpose of autoload_static is to generate a script tag to put in some other external template, what would a template on curdoc even do in that case?

You can definitely file a GitHub Issue about this, but I’ll state ahead of time that outcomes like wontfix, or working as intended, or even a discussion to deprecate and remove autoload_static altogether are at least equally likely outcomes as any work to make these two features work together (for some definition of “work”).


  1. A cursory search of all of GitHub reveals maybe ~100 usages in ten years. ↩︎

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.