Intento obtener el resultado de Input('demo-dropdown', 'selection')
pero la seleccion me devuelve None
. En efecto, en app.py construi el mio dropdown en app.py
:
import dash_daq as daq
import plotly.graph_objects as go
import dash_core_components as dcc
import dash_html_components as html
import datetime as dt
from .server import app, server
from .callbacks import (search)
def article_search():
return html.Div(
[
# Value we searc in the text
html.Div(dcc.Input(id='input-box', type='text')),
# Dropdown
html.Div([
dcc.Dropdown(
id='demo-dropdown',
options=[
{'label': 'khazaradze', 'value': 'khazaradze'},
{'label': 'gakharia', 'value': 'gakharia'}
],
value='khazaradze'
),
html.Div(id='dd-output-container')
]),
# Date picker, to be change to a range selector
html.Div([
dcc.DatePickerRange(
id='my-date-picker-range',
min_date_allowed=dt.datetime(1995, 8, 5),
max_date_allowed=dt.datetime.today(),
initial_visible_month=dt.datetime(2017, 8, 5),
end_date=dt.datetime.today()
),
html.Div(id='output-container-date-picker-range')
]),
html.Button('Submit', id='button'),
html.Div(id='output-container-button',
children='Enter a value and press submit'),
html.H6(
id='articles',
children='Matching articles',
)
]
)
app.layout = html.Div(
[
# empty Div to trigger javascript file for graph resizing
html.Div(id="output-clientside"),
# Header
header(),
dcc.Tabs(
[
dcc.Tab(
label='Search article',
value='search',
children=article_search()
)
]
)
]
)
Se parece a esto:
Y el call back en search.py
:
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import datetime as dt
import pickle
from ..server import app
@app.callback(
# Output('output-container-button', 'children'),
Output('articles', 'children'),
[Input('button', 'n_clicks'),
Input('my-date-picker-range', 'start_date'),
Input('my-date-picker-range', 'end_date'),
Input('demo-dropdown', 'selection')], # returns None ?
[State('input-box', 'word')])
def update_search(n_clicks, start_date, end_date, word, selection):
print(selection)
Pero esto me devuelve None
cuando hago un clic sobre Submit
.
Ahora State('input-box', 'word')
tambien me devuelve None
.