☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Using CustomJS to make API call don't return a correct object

Community Support
koladev
koladev

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', ...)
⌁   Link to post
p-himik
p-himik

OK. But they’re the ones that causing the problem. source doesn’t have close or open attributes. It has data attribute which might have the keys (not attributes) close and open, if the data available by that URL has them. And even then, the data will not be available right when you create the data source - it will be available only after some time the web page is rendered.

⌁   Link to post

End of archived discussion · Replies are disabled