Hello. I’ve been trying to find a way to use AjaxDataSource to retrieve a JSON object. I used CustomJS model to convert the object into a bokeh format but it’s not working as excepted.
Here the code:
adapter = CustomJS(
code = """
const result = {
date:[],
open:[],
close:[],
high:[],
low:[]
};
const time_series = cb_obj.response["Time Series (5min)"];
for(date in time_series){
result.date.push(date);
result.open.push(time_series[date]['1. open']);
result.high.push(time_series[date]['2. high']);
result.low.push(time_series[date]['3. low']);
result.close.push(time_series[date])['4. close'];
}
console.log(result);
return result;
""")
source = AjaxDataSource(data_url='https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=AAPL&interval=5min&apikey=API_KEY',
polling_interval=100, adapter=adapter)
print("Here is source : ",adapter)
increasing = source.close > source.open
decreasing = source.open > source.close
Error
'AjaxDataSource' object has no attribute 'close'
Variable Value
adapter
CustomJS(id='1001', ...)
request
<WSGIRequest: GET '/'>
source
AjaxDataSource(id='1002', ...)