Thanks for responding!
Below is the entire code (or the part relevant to the dashboard itself). There are two important homemade functions in there (package mobdna_elastic), but they’re just df manipulation functions. To reproduce this, it should suffice to assign another dataframe to the df variable.
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_table_experiments as dt
from dash.dependencies import Input, Output, State
import mobdna_elastic
app = dash.Dash()
app.scripts.config.serve_locally = True
app.layout = html.Div([
html.H1(children='Dash'),
html.Div(dcc.Input(id='input-box', type='text')),
html.Button('Add', id='add-button'),
html.Div(id='output-container-button',
children='Enter an id'),
html.Div(
dcc.Dropdown(
id='dropdown',
options=[{'label': 'c2fde36b-0433-4a7c-ad33-b81659550525',
'value': 'c2fde36b-0433-4a7c-ad33-b81659550525'}],
multi=True,
clearable=True,
value=[]
)
),
html.Hr(), # horizontal line
html.Button('Fetch', id='fetch-button'),
html.Button('Export', id='export-button'),
html.Hr(), # horizontal line
html.Div(id='output-data-upload'),
html.Div(dt.DataTable(rows=[{}]), style={'display': 'none'})
])
app.css.append_css({"external_url": "http://users.ugent.be/~wdurnez/css/stylish-portfolio.css"})
def display(ids):
data = mobdna_elastic.fetch(doc_type='appevents', ids=ids)
df = mobdna_elastic.to_df(data=data)
return html.Div([
dt.DataTable(rows=df.to_dict('records')),
html.Hr() # horizontal line
])
@app.callback(
Output('output-container-button', 'children'),
[Input('add-button', 'n_clicks')],
[State('input-box', 'value')])
def update_output(n_clicks, value):
return 'The input value was "{}" and the button has been clicked {} times'.format(
value,
n_clicks
)
# Add ids
@app.callback(
Output('dropdown', 'options'),
[Input('add-button', 'n_clicks')],
[State('dropdown', 'options'),
State('input-box', 'value')])
def update_options(n_clicks, existing_ids, value):
option = {
'label': value,
'value': value}
option_none = {
'label': None,
'value': None
}
if option not in existing_ids:
existing_ids.append(option)
if len(existing_ids) > 1 and option_none in existing_ids:
existing_ids.remove(option_none)
return existing_ids
# Get data and display
@app.callback(Output('output-data-upload', 'children'),
[Input('fetch-button', 'n_clicks')],
[State('dropdown', 'value')])
def update_table(n_clicks, value):
print(len(value))
if len(value) >= 1:
# return display(value)
print('check')
if __name__ == '__main__':
app.run_server(debug=True)