Created
December 15, 2021 00:10
-
-
Save pmbaumgartner/be107afe590529b4d5244e288cade5b3 to your computer and use it in GitHub Desktop.
simple app for clicking on data to label
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 import dcc | |
from dash import html | |
from dash.dependencies import Input, Output | |
import json | |
clicked = [] | |
external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"] | |
app = dash.Dash(external_stylesheets=external_stylesheets) | |
app.layout = html.Div( | |
[ | |
dcc.Graph(figure=fig, id="graph"), | |
html.Strong("Clicked Data"), | |
html.Div(html.Pre([], id="click-data", style={"background-color": "#eeeeee"})), | |
] | |
) | |
def getdata(click_data): | |
point = click_data["points"][0] | |
data = dict(zip(point_customdata, point["customdata"])) | |
return data | |
@app.callback( | |
Output("click-data", "children"), | |
Input("graph", "clickData"), | |
prevent_initial_call=True, | |
) | |
def display_click_data(clickData): | |
global clicked | |
data = getdata(clickData) | |
if data not in clicked: | |
clicked.append(data) | |
return json.dumps(clicked, indent=2) | |
app.run_server( | |
debug=True, use_reloader=False, port=9877 | |
) # Turn off reloader if inside Jupyter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment