DashIntro
DashIntro copied to clipboard
app.callbacks
Hi, I'm able to run the first tutorial example in an AWS SageMaker notebook by modifying show_app
and app
as follows:
def show_app(app, port = 8000,
width = 800,
height = 500,
offline = True):
def get_notebook_name():
log_path = '/opt/ml/metadata/resource-metadata.json'
with open(log_path, 'r') as logs:
_logs = json.load(logs)
return _logs['ResourceName']
url = f'https://{get_notebook_name().lower()}.notebook.us-east-1.sagemaker.aws/proxy/{port}'
iframe = f'<a href="{url}" target="_new">Open in new window</a><hr><iframe src="{url}" width={width} height={height}></iframe>'
display.display_html(iframe, raw = True)
if offline:
app.css.config.serve_locally = True
app.scripts.config.serve_locally = True
return app.run_server(debug=False,
port=port)
app = dash.Dash(requests_pathname_prefix='/proxy/8000/')
However callbacks functionality doesn't seem to work. Is there any network settings I'm missing that would have to be modified for callbacks?
Here's a minimal non-working example:
app.layout = html.Div([
dcc.Input(id='my-id', value='initial value', type="text"),
html.Div(id='my-div')
])
@app.callback(
Output(component_id='my-div', component_property='children'),
[Input(component_id='my-id', component_property='value')],
)
def update_output_div(input_value):
return 'You\'ve entered "{}"'.format(input_value)
Which results in this error:
Exception on /_dash-update-component [POST] Traceback (most recent call last): File "/home/ec2-user/anaconda3/envs/python3/lib/python3.6/site-packages/werkzeug/serving.py", line 124, in read_chunk_len _len = int(line.strip(), 16) ValueError: invalid literal for int() with base 16: '{"output":"my-div.children","outputs":{"id":"my-div","property":"children"},"inputs":[{"id":"my-id","property":"value","value":"initial value"}],"changedPropIds":[]}'