Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

Problem with html.Datalist

$
0
0

@JoseMarqueses wrote:

hi,
I have a code with a dcc.Input and html.Datalist. Well. When I introduce “lion” in input all is correct, but when I introduce "lion " ( with space ) the result is different and would be the same. why?

import dash
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
import pandas as pd
from dash.dependencies import Input, Output, State

data_aux = pd.DataFrame()
data_aux["Nombre"] = ['Lionel Messi', 'Isaac Capriglione', 'Giammaria Maglione', 'Markus Palionis', 'Maxime Allione', 'Lionel Mallein', 'Paolo Ghiglione', 'Paolo Ghiglione', 'Elion Minaj', 'Lionel Carole', 'Lionn', 'Lion Kalentjev', 'Million Manhoef', 'Elion Spahija', 'Giorgio Lionetti', 'Antonio Tartaglione', 'Federico Coniglione', 'Saul Castiglione', 'Domenico Zampaglione', 'Lionnel Yakam']


app = dash.Dash(__name__)

app.layout = html.Div(
    children=[
        dcc.Input(id='input-1',
            type='text',
            list='list',
        ),
        html.Datalist(
            id='list',
            children=[]
        ),
        html.Div(id="kk")
    ]
)

@app.callback(
    Output('kk','children'),
    [Input('list','children')]
)
def kk1(children):
    return children
    
@app.callback(
    Output('list','children'),
    [Input('input-1','value')]
)
def kk(inputvalue):
    if inputvalue:
        data_aux1 = data_aux.copy()
        for i in inputvalue.split(" "):
            data_aux1 = data_aux1[data_aux1['Nombre'].str.contains("(?i){}".format(str(i)))==True]
        return [html.Option(value=word) for word in data_aux1["Nombre"][0:20].to_list()] 

if __name__ == "__main__":
    app.run_server()

Nevertheless, if you run this code in line command (the same as above), works! I dont undertand what happen:

import pandas as pd

data_aux = pd.DataFrame()

data_aux["Nombre"] = ['Lionel Messi', 'Isaac Capriglione', 'Giammaria Maglione', 'Markus Palionis', 'Maxime Allione', 'Lionel Mallein', 'Paolo Ghiglione', 'Paolo Ghiglione', 'Elion Minaj', 'Lionel Carole', 'Lionn', 'Lion Kalentjev', 'Million Manhoef', 'Elion Spahija', 'Giorgio Lionetti', 'Antonio Tartaglione', 'Federico Coniglione', 'Saul Castiglione', 'Domenico Zampaglione', 'Lionnel Yakam']

data_aux1 = data_aux.copy()
inputvalue = "lion "
for i in inputvalue:
    data_aux1 = data_aux1[data_aux1['Nombre'].str.contains("(?i){}".format(i))==True]
print(data_aux1)```

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 6271

Latest Images

Trending Articles



Latest Images