The code in my SO post is indeed the one from the example, because even the example isn’t working and is throwing the error (BOTH_CHILD_AND_ROOT) !
My own code may have other problems which I didn’t want people to focus on.
Anyway, here goes my own code.
def bokeh_temperature_scatter_plot():
data_set = CSVModel.objects.all()
x_data = []
y_data = []
for Model in data_set:
x_data.append(Model.cpu)
y_data.append(Model.temperature)
dic = {'cpu': x_data, 'temperature': y_data}
df = pd.DataFrame(dic)
p = Scatter(df, x='cpu', y='temperature', title=u'Temperature vs CPU', color=u'navy', xlabel=u'CPU in MB'\
, ylabel=u'Temperature °C' )
colors = RdBu9
box_cold = BoxAnnotation(plot=p, top=50, fill_alpha=0.1, fill_color=colors[0])
box_normal = BoxAnnotation(plot=p, bottom=50, top=100, fill_alpha=0.1, fill_color=colors[4])
box_hot = BoxAnnotation(plot=p, bottom=100, fill_alpha=0.1, fill_color=colors[7])
p.renderers.extend([box_cold, box_normal, box_hot])
return p
def bokeh_bar_chart_test():
data_set = CSVModel.objects.all()
x_data = []
y_data = []
dic = {'values': {}}
for Model in data_set:
x_data.append(Model.date)
y_data.append(Model.cpu)
x_test = [x.strftime("%Y-%m-%d") for x in x_data]
for x in x_test:
i = x_test.index(x)
dic['values'][x]=y_data[i]
df = pd.DataFrame(dic)
p = Bar(df, agg='count', values='values', title='Quantity sold by model', color='blue', width = 800,\
tools=[HoverTool()])
hover = p.select_one(HoverTool)
hover.point_policy = "follow_mouse"
hover.tooltips = [
("CPU", "$y"),
("Date", "@x")
]
return p
In a python console :
from functions import bokeh_xml_test, bokeh_bar_chart_test
from bokeh.io import vform
form = vform (bokeh_xml_test(),bokeh_bar_chart_test())
show(form)
This only shows a blank page.
Then, if I add an output_file and retrieve an html file and opens it in my browser, the same thing happens. And the same thing if I retrieve javascript et div like that :
javascript, div = components(vform)
and add these in an html file.
Thanks for taking the time to help me solve this.