Building Dashboards with Dash and Plotly
Alex Scriven
Data Scientist
A familiar bar chart and text component:
# Create figure & dash.Dash() html.Div(children=[ dcc.Graph(id='bar_fig', figure=ecom_bar),
html.Br(), html.H2("The Hover Data:"), html.P(id='text_output')
Set up a callback
@app.callback( Output('text_output', 'children'), Input('bar_fig', 'hoverData'))
def capture_hover_data(hoverData): return str(hoverData)
What happens:
hoverData
property of the figure changes.P()
tag
hoverData
ecom_scatter = px.scatter(ecom_data,
x='Total Sales ($)',
y='Sales Volume', color='Country',
custom_data=['Country'])
customData
contains the country!
clickData
property)@app.callback(
Output('text_output', 'children'),
Input('bar_fig', 'clickData'))
def capture_hover_data(clickData):
return str(clickData)
Building Dashboards with Dash and Plotly