Skip to content
Advertisement

How create a dynamic search results in a html list using dash/python, live results without submit botton

I am trying to create a dynamic search-box that allows doing research and auto-completion. I would like that when I type in a search box without pushing a button I have an HTML.Div with results. Exactly how it works in the yahoo finance search box. I am trying it but I have no good results, first it is very slow and it works just when I click the pointer outside the search box, so it is not live, second, gives me back just the last result. Instead, I need all the results to pop-up in an HTML div and not in a dropbox. I tried to do this:

JavaScript

how to do this? I am trying and trying but without results. Some help?

ok let suppose this is my json data:

JavaScript

Now I use an input box (search box) to get these results/auto-compete suggestions. how can I create a search box that gives me an HTML table with all these results?

Advertisement

Answer

I’m not sure what this is supposed to do:

JavaScript

but I’m not sure it’s what you want. When I enter the text “hello”, the values in list_c are:

JavaScript

That doesn’t seem useful.

There’s nothing wrong with taking the input, like you are, and outputting directly to the div, but this is not written in a way that can be fast at all. It’s performing API requests something like 20+ times every time the callback is fired. That takes a bit. For it to be really fast you’d need to do at most 1 API request per callback execution.

You also have no initial value for longname, so the callback could end up returning None if that variable is never defined.

how can I create a search box that gives me an HTML table with all these results?

You can loop over the results and fit them into a table with the format you want. Here is a very simple table I created. It worked when I ran it locally using your sample data as DATA

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement