Hello,
I am looking for some guidance, as searching on the internet and through the issues didn’t pan out what I was looking for. I am working with Bokeh (v2.4.3), created a standalone app that uses jinja2 templates with bootstrap. This is following the directory structure project.
The bokeh server serves all the content with bokeh serve --allow-websocket-origin=localhost:8000 myapp
, including css, js and all the layouts I set up in the template accessed from http://localhost:5006
I then wanted to integrate this with django (v4+), and saw the pull_session
, server_session
and server_document
functions. However, these just return a script, which when embedding into my template from django, only renders the components as defined in the bokeh myapp/main.py
, with none of the css or any layouts before as defined in the templates folder of the bokeh app.
eg.
# End of myapp/main.py
...
p = figure(..., name="myplot")
select = Select(..., name="myselect")
...
curdoc().add_root(p)
curdoc().add_root(slider)
# and more components
# django views.py
def myview(request)
with pull_session(url="http://localhost:5006/myapp") as session:
script = server_session(session_id=session.id, url="http://localhost:5006/myapp")
return render(request, 'mydjangotemplate.html', {"script" : script})
<!-- mydjangotemplate.html -->
{% extends base.html %}
{% block content %}
{{ script | safe }}
{% endblock %}
<!-- base.html -->
<!doctype html>
<html>
<head>
<!-- CSS/JS only for django, not bokeh server -->
<link href="{% static "css/bootstrap/bootstrap.min.css" %}" rel="stylesheet">
<link href="{% static "css/mystyle.css" %}" rel="stylesheet">
</head>
<body>
<!-- Other layout code for main site functionality -->
{% block content %}
{% endblock %}
<!-- end of main site layout -->
</body>
</html>
My question is, do I need to pass the bootstrap CSS/JS and bokehJS files to the django template? Or am I approaching this wrong? Which I feel is the case. My impression was to just embed the view where the {{ script |safe }}
would go. I double checked using the bokeh built-in layouts and those work fine, but I would like to have mobile and responsive layouts.
Any advice or help would be greatly appreciated!
Cheers,
PS. An testable example would be embedding the bokeh.git/examples/app/dash app into a django template.