Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

javascript - bokeh autocomplete, with server side update of the suggestions

For an autoComplete textInput in bokeh i have a list of suggestions. When there is a search term dat is not in that list, I can update that list of suggestions via a python callback. When the update is done fast, the new inserted suggestions appear in the dropdown. However when this updating of the suggestions takes few seconds, they are there, but the dropdown does not appear. The script below gives the desired result when you remove the time.sleep(2) line. Otherwise it doesn't work.

from bokeh.io import curdoc
from bokeh.models import AutocompleteInput
import time

completions=['apple','pen','pineapple']

def getSlowSuggestions():
    time.sleep(2)
    return ['car','cat','cow']

def update_options(attr,old,new):
    global code
    inCompletions=False
    for s in completions:#check if the term is in the completions
        if new in s:
            inCompletions=True
    if inCompletions==False:#add new the completions
        completions.extend(getSlowSuggestions())
        autocomp.completions=completions

autocomp = AutocompleteInput(value='',
                             completions=completions,
                             min_characters=1,
                             width=700,height=40,
                             case_sensitive=False)
autocomp.on_change('value_input',update_options)
def update_completions(attr,old,new):
    print('updated completions')
    autocomp.trigger()
autocomp.on_change('completions',update_completions)

curdoc().add_root(autocomp)

This is what i get: enter image description here

This is what i want of course: enter image description here

I have tried a few things like calling autocomp.trigger() after completions are done but without success.

question from:https://stackoverflow.com/questions/65890774/bokeh-autocomplete-with-server-side-update-of-the-suggestions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...