I have problem with passing login data to API with Dash. My app looks like this: I have index.py where I have two tabs with data and settings , app.py with basic configuration and apps package, where I have 2 separate modules for each tab. I have created login instance in my app.py:
server = flask.Flask(__name__)
app = dash.Dash(__name__, server=server)
app.config.suppress_callback_exceptions = True
primary_key = 'x'
private_key = 'x'
manager = Recognition(primary_key, private_key)
And made Inputs layout in settings ‘tab’:
layout = [
html.Div([
html.Div(
[
html.H3("Primary API key"),
dcc.Input(
id='primary-key',
placeholder='Enter a value...',
type='text',
style = {"width":"50%"}
),
html.H3("Private API key"),
dcc.Input(
id='private-key',
placeholder='Enter a value...',
type='text',
style = {"width":"50%"}
),
],
),
html.Button('Submit', id='button', className='btn btn-primary'),
html.Div(id='output-hidden')
])
]
@app.callback(
Output('output-hidden', 'children'),
[Input('button', 'n_clicks')],
[State('primary-key', 'value'),
State('private-key', 'value')]
)
def update_output(n_clicks, value1, value2):
print(manager.api_key)
manager.api_key = value1
manager.api_secret = value2
print(manager.api_key)
I imported variables from app.py etc. and what i want to do is to paste API keys into inputs, click submit and update values from app.py and it is working until I am on settings tab. When i switch to data tab keys return to it’s initial value ‘x’. What should I do to make it work as I intend?