Skip to content

Instantly share code, notes, and snippets.

Last active November 13, 2019 05:08
What would you like to do?
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import as px
gapminder ="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),
@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__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment