Hi,
here are codesnippest you should clue together to a working
AjaxDataSource with django:
**app/views.py**
from django.views import generic
from django.http import JsonResponse
from bokeh.plotting.figure import figure
from bokeh.models.sources import AjaxDataSource
from bokeh.models.markers import Circle
from bokeh.embed import components
class PlotView(generic.TemplateView):
'''
Static Bokeh Plot
'''
template_name = 'app/plot.html'
def get_context_data(self, **kwargs):
c = generic.TemplateView.get_context_data(self, **kwargs)
plot = figure()
data_url = str(reverse_lazy('app:plot_data'))
source = AjaxDataSource(data=dict(timestamp=[], x=[],
y=, color=, alpha=, id=),
data_url=data_url,
polling_interval=4000,
method=‘GET’, mode=‘replace’)
circle = Circle(x=“x”, y=“y”, size=15, fill_color=“color”,
line_color=None)
plot.add_glyph(source, circle)
c[‘plot_js’], c[‘plot_div’] = components(plot)
return c
class PlotDataView(generic.View):
'''
Deliver Json Data for the AjaxDataSource
'''
def get(self, request, *args, **kwargs):
import random
return JsonResponse(dict(x=[1,2,3],
y=[random.random(),random.random(),random.random()],
color=[‘blue’, ‘green’, ‘red’]))
**app/urls.py
** from django.conf.urls import url
from . import views
urlpatterns = [ url(r'^plot/$', views.PlotView.as_view(), name='plot'),
url(r'^plot_data/$', views.PlotDataView.as_view(),
name=‘plot_data’),
]
**template/app/plot.html (make sure bokeh js and css is included)**
{% block content %}
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Pair Plot</h1>
</div>
</div>
<div class="bk-root">
{{ plot_div|safe }}
</div>
{{plot_js|safe }}
{% endblock %}
···
On 2017-09-27 04:04, Allan wrote:
Hey, so I'm testing out using AjaxDataSource to
load my data periodically. I’m working with Django and worked
off an example that was posted here some time ago. However, it
seems when I load my page, the polling_interval isn’t actually
being used, it just loads the data from the data url all at
once. I thought that it would grab a piece of data from the
huge list one at a time per the interval. Am I misunderstanding
something? How can I make it grab data as per a certain amount
and per time interval?Thanks!
–
You received this message because you are subscribed to the Google
Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it,
send an email to [email protected].
To post to this group, send email to [email protected]. To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/88d4b4b4-5280-4179-828f-9bd5f431ae94%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/88d4b4b4-5280-4179-828f-9bd5f431ae94%40continuum.io?utm_medium=email&utm_source=footer). For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).