Skip to content

Commit 95730fc

Browse files
committed
Shuffle keypoints when changing image
1 parent d42402c commit 95730fc

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

app.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ def save_data(click_s, ind_image):
3737
print(xy, ind_image)
3838

3939

40+
@view.app.callback(
41+
Output('radio', 'options'),
42+
[Input('next', 'n_clicks'),
43+
Input('previous', 'n_clicks')]
44+
)
45+
def refresh_radio_buttons(click_n, click_p):
46+
if not (click_n or click_p):
47+
return dash.no_update
48+
return view.refresh_radio_buttons()
49+
50+
4051
@view.app.callback(
4152
[Output('canvas', 'figure'),
4253
Output('radio', 'value'),
@@ -66,7 +77,6 @@ def update_image(clickData, relayoutData, click_n, click_p, click_c, slider_val,
6677

6778
if ind_image is None: ind_image = 0
6879
shapes = [] if shapes is None else json.loads(shapes)
69-
n_bpt = view.options.index(option)
7080

7181
ctx = dash.callback_context
7282
event = ctx.triggered[0]['prop_id']
@@ -124,6 +134,7 @@ def update_image(clickData, relayoutData, click_n, click_p, click_c, slider_val,
124134
elif 'autorange' in key:
125135
view.fig.update_xaxes(autorange=True)
126136
view.fig.update_yaxes(autorange='reversed')
137+
n_bpt = view.options.index(option)
127138
if button_id != 'slider' and 'relayout' not in event:
128139
n_bpt += 1
129140
new_option = view.options[min(len(view.options) - 1, n_bpt)]

view.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, name, db, config, server):
1616
self.current_idx = 0
1717
self.username = str(uuid.uuid4())
1818
self.appconfig = config
19-
self.subset = random.sample(range(len(config.options)), config.n2show)
19+
self.pick_keypoint_subset()
2020
self.make_figure_image(self.current_idx)
2121
self.app.layout = self.make_layout()
2222

@@ -120,3 +120,10 @@ def make_layout(self):
120120
html.Div(id='shapes', style={'display': 'none'})
121121
]
122122
)
123+
124+
def pick_keypoint_subset(self):
125+
self.subset = random.sample(range(len(self.appconfig.options)), self.appconfig.n2show)
126+
127+
def refresh_radio_buttons(self):
128+
self.pick_keypoint_subset()
129+
return [{'label': opt, 'value': opt} for opt in self.options]

0 commit comments

Comments
 (0)