@@ -250,6 +250,8 @@ def update_transformation(enabled, states):
250
250
# TODO: move callback inside AllTransformationsComponent for efficiency?
251
251
252
252
kwargs = self .reconstruct_kwargs_from_state (dash .callback_context .states )
253
+ # for debug
254
+ # print("transformation kwargs", kwargs)
253
255
254
256
if not enabled :
255
257
input_state = (False ,) * len (states )
@@ -286,7 +288,16 @@ def __init__(
286
288
* args ,
287
289
** kwargs ,
288
290
):
291
+ """
292
+ Create a component that can manage multiple transformations in a
293
+ user-defined order.
294
+
295
+ :param transformations: if provided, only offer a subset of available
296
+ transformaitons, provide as a string of the given transformation name
297
+ :param input_structure_component: will supply the structure to transform
298
+ """
289
299
300
+ # get available transformations
290
301
subclasses = TransformationComponent .__subclasses__ ()
291
302
subclass_names = [s .__name__ for s in subclasses ]
292
303
@@ -306,6 +317,8 @@ def __init__(
306
317
self .links ["input_structure" ] = input_structure_component .id ()
307
318
self .create_store ("input_structure" )
308
319
320
+ self .create_store ("enabled-transformations" , initial_data = [])
321
+
309
322
transformations = [
310
323
t (input_structure_component_id = self .id ("input_structure" ))
311
324
for t in transformations
@@ -370,11 +383,12 @@ def apply_transformation(transformation_data, struct):
370
383
371
384
struct = transformation .apply_transformation (struct )
372
385
except Exception as exc :
373
- error_title = (
386
+ error_title = html . Span (
374
387
f'Failed to apply "{ transformation .__class__ .__name__ } " '
375
388
f"transformation: { exc } "
376
389
)
377
390
traceback_info = Reveal (
391
+ id = self .id ("Error" ),
378
392
title = html .B ("Traceback" ),
379
393
children = [dcc .Markdown (traceback .format_exc ())],
380
394
)
@@ -385,12 +399,15 @@ def apply_transformation(transformation_data, struct):
385
399
@app .callback (
386
400
Output (self .id ("transformation_options" ), "children" ),
387
401
[
388
- Input (self .id ("choices" ), "value" ),
389
402
Input (self .id ("input_structure" ), "data" ),
403
+ Input (self .id ("choices" ), "value" ),
390
404
],
391
405
[State (t .id (), "data" ) for t in self .transformations .values ()],
392
406
)
393
- def show_transformation_options (values , structure , * args ):
407
+ def show_transformation_options (structure , values , * args ):
408
+
409
+ # for debug
410
+ # print(dash.callback_context.triggered)
394
411
395
412
values = values or []
396
413
@@ -408,11 +425,27 @@ def show_transformation_options(values, structure, *args):
408
425
return [transformation_options ]
409
426
410
427
@app .callback (
411
- [Output (self .id (), "data" ), Output (self .id ("error" ), "children" )],
428
+ Output (self .id ("enabled-transformations" ), "data" ),
429
+ Input (self .id ("choices" ), "value" ),
430
+ )
431
+ def set_enabled_transformations (value ):
432
+ """
433
+ This is due to an unfortunate but noisy bug that
434
+ complains that this specific input is not present
435
+ in the layout on load.
436
+ """
437
+ return value
438
+
439
+ # TODO: make an error store too
440
+
441
+ @app .callback (
442
+ # [
443
+ Output (self .id (), "data" ),
444
+ # Output(self.id("error"), "children")],
412
445
[Input (t .id (), "data" ) for t in self .transformations .values ()]
413
446
+ [
414
447
Input (self .id ("input_structure" ), "data" ),
415
- Input (self .id ("choices " ), "value " ),
448
+ Input (self .id ("enabled-transformations " ), "data " ),
416
449
],
417
450
)
418
451
def run_transformations (* args ):
@@ -424,6 +457,9 @@ def run_transformations(*args):
424
457
user_visible_transformations = args [- 1 ]
425
458
struct = self .from_data (args [- 2 ])
426
459
460
+ # for debug
461
+ # print("input struct", struct)
462
+
427
463
errors = []
428
464
429
465
transformations = []
@@ -432,7 +468,7 @@ def run_transformations(*args):
432
468
transformations .append (transformation )
433
469
434
470
if not transformations :
435
- return struct , html .Div ()
471
+ return struct # , html.Div()
436
472
437
473
for transformation_data in transformations :
438
474
@@ -478,7 +514,10 @@ def run_transformations(*args):
478
514
]
479
515
)
480
516
481
- return struct , error_msg
517
+ # for debug
518
+ # print("transformed struct", struct)
519
+
520
+ return struct # , error_msg
482
521
483
522
# callback to take all transformations
484
523
# and also state of which transformations are user-visible (+ their order)
0 commit comments