Hello, everyone!
I am trying to use the fantastic package dash to produce something that could help a lot in the daily work, and I’ve met a small problem:
I need to dynamically change the options of a Dropdown/Checklist with a dict input from other programs, but I am currently not capable of replacing the existing dcc component with the dynamic input, is there anyway that could help me out here?
Below is my original thought to make it through, which is not working when the update_the_dash function is called.
It would be considerably helpful if anyone could offer some suggestions. Thank you soooooo much =)
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
import pandas as pd
app = dash.Dash()
app.layout = html.Div([
html.Div([
html.Div([
dcc.Dropdown(
id = 'selected-strategy',
options = [
{'label': 'raw', 'value': 0 },
{'label': 'adverse', 'value': 1 },
{'label': 'zero', 'value' : 2}
],
multi=True,
value = [0],
),
],
style = {'width' : '69%', 'display':'inline-block'}),
html.Div([
dcc.RadioItems(
id = 'selected-data-shown',
options = [
{'label': 'absolute return', 'value' : 0},
{'label': 'excess return', 'value' : 1}
],
value = [0]
)
],
style = {'width' : '29%', 'float': 'right', 'display': 'inline-block'})
])
])
def update_the_dash(optionsDict):
dcc.Checklist(
id = 'input-the-choices',
options = [{'label': keyLabel, 'value': optionsDict[keyLabel]} for keyLabel in optionsDict]
)
@app.callback(dash.dependencies.Output('selected-strategy', 'options'),
[dash.dependencies.Input('input-the-choices', 'options')])
def set_selected_strategy(optionsDict):
return optionsDict
app.run_server(debug = True)
if __name__ == '__main__':
print([dash.dependencies.Input('selected-strategy', 'options')])
app.run_server(debug=True)