-
-
Save chriddyp/1a95f6582a5256db9847086232987bff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dash | |
import dash_core_components as dcc | |
import dash_html_components as html | |
import plotly.graph_objs as go | |
import pandas as pd | |
app = dash.Dash() | |
df = pd.read_csv( | |
'https://raw.githubusercontent.com/' | |
'plotly/datasets/master/' | |
'1962_2006_walmart_store_openings.csv') | |
app.layout = html.Div([ | |
html.H1('Walmart Store Openings'), | |
html.Div(id='text-content'), | |
dcc.Graph(id='map', figure={ | |
'data': [{ | |
'lat': df['LAT'], | |
'lon': df['LON'], | |
'marker': { | |
'color': df['YEAR'], | |
'size': 8, | |
'opacity': 0.6 | |
}, | |
'customdata': df['storenum'], | |
'type': 'scattermapbox' | |
}], | |
'layout': { | |
'mapbox': { | |
'accesstoken': 'pk.eyJ1IjoiY2hyaWRkeXAiLCJhIjoiY2ozcGI1MTZ3MDBpcTJ3cXR4b3owdDQwaCJ9.8jpMunbKjdq1anXwU5gxIw' | |
}, | |
'hovermode': 'closest', | |
'margin': {'l': 0, 'r': 0, 'b': 0, 't': 0} | |
} | |
}) | |
]) | |
@app.callback( | |
dash.dependencies.Output('text-content', 'children'), | |
[dash.dependencies.Input('map', 'hoverData')]) | |
def update_text(hoverData): | |
s = df[df['storenum'] == hoverData['points'][0]['customdata']] | |
return html.H3( | |
'The {}, {} {} opened in {}'.format( | |
s.iloc[0]['STRCITY'], | |
s.iloc[0]['STRSTATE'], | |
s.iloc[0]['type_store'], | |
s.iloc[0]['YEAR'] | |
) | |
) | |
app.css.append_css({ | |
'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css' | |
}) | |
if __name__ == '__main__': | |
app.run_server(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry, html.Div(id='text-content') is correct, you do not need edit it.
The input data is comes from Graph "map", in line 18. You should inspect the dcc.Graph definition from official doc, it should have an attribute 'value' or something.