import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
app = dash.Dash()
df = pd.read_csv(
'https://gist.githubusercontent.com/chriddyp/' +
'5d1ea79569ed194d432e56108a04d188/raw/' +
'a9f9e8076b837d541398e999dcbac2b2826a81f8/'+
'gdp-life-exp-2007.csv',index_col=0)
uniq_cont=df.continent.unique()
app.layout = html.Div([
html.H4(children='US Agriculture Exports (2011)'),
html.Label('Continent '),
html.Div([
dcc.Dropdown(
id='xdropdown',
options=[{'label': i, 'value': i} for i in uniq_cont],
value='Asia',
)],
style={'width': '38%', 'display': 'inline-block'}),
dcc.Textarea(
id='my_text',
placeholder='Enter a value...',
value='',
style={'width': '100%'}
),
dcc.Graph(id='graph-with-dropdown')
])
@app.callback(
dash.dependencies.Output('graph-with-dropdown','figure'),
[dash.dependencies.Input('xdropdown','value')
#,dash.dependencies.Input('ydropdown', 'value')
])
def update_graph(xdropdown):
dff = df[df['continent'] == xdropdown]
return {'data':[go.Scatter(x=dff[dff['continent'] == xdropdown]['life expectancy'],y=dff[dff['continent'] == xdropdown]['gdp per capita'],text=dff[dff['continent'] == xdropdown]['country'],mode='markers',marker={'size': 15,'opacity': 0.5,'line': {'width': 0.5, 'color': 'white'}
})],
'layout': go.Layout(
xaxis={
'title':'life expectancy',
},
yaxis={
'title': 'gdp per capita',
},
margin={'l': 40, 'b': 40, 't': 10, 'r': 0},
hovermode='closest')}
@app.callback(
# dash.dependencies.Output('text_area', component_property='children'),
# [dash.dependencies.Input(component_id='my-id', component_property='value')])
def update_output_div(xdropdown):
return {print('{:.1f}'.format(df[df['continent']==xdropdown].describe().describe().loc['mean','life expectancy']))}
if __name__ == '__main__':
app.run_server(debug=True)
Iām a new user to DASH , would like to update the mean of selected continent in the textarea space but not sure how to call dependencies for text_area .
Thanks in advance .