Last active
November 13, 2019 05:08
-
-
Save nicolaskruchten/4721e5ee190d35c80d47a71c3d427174 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 | |
from dash.dependencies import Input, Output | |
import dash_core_components as dcc | |
import dash_html_components as html | |
import plotly.express as px | |
gapminder = px.data.gapminder().query("year == 2007") | |
input_figure = px.scatter(gapminder, x="gdpPercap", y="lifeExp", size="pop", | |
custom_data=[gapminder.index], # this is the special bit! | |
log_x=True, size_max=60, height=400).update_layout(dragmode='lasso') | |
app = dash.Dash(__name__) | |
app.layout = html.Div([dcc.Graph(id='input-figure', figure=input_figure), | |
dcc.Graph(id='output-figure')]) | |
@app.callback(Output('output-figure', 'figure'), | |
[Input('input-figure', 'selectedData')]) | |
def display_selected_data(selectedData): | |
df = gapminder | |
if selectedData: | |
indices = [point["customdata"][0] for point in selectedData["points"]] | |
df = df.loc[indices] | |
return px.scatter_geo(df, locations="iso_alpha", size="pop", height=400) | |
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