9. HTML tables and steps
Reading and writing HTML tables in the body, and working with Steps (checklists). Experiments and Resource items work the same way.
The short version
tables = elab.experiments.entry(experiment_id).tables # for an item: elab.items.entry(item_id).tables
tables.list(debug=True) # tables in the body
tables.get_horizontal(table_index=0) # values of the first (horizontal) table
steps = elab.experiments.entry(experiment_id).steps
steps.set_finished_by_body("analysis script", finished=True)HTML tables
Table types
- Horizontal table: the first row is a header, data rows follow. Values are matched to header names.
- Vertical table: the left column holds keys, the right column values.
Updating a horizontal table
update_contents = [
{
"Proposal": "2026T0001",
"Sample ID": "99",
"Note": "table updated",
},
]
tables.update_horizontal(
update_contents,
table_index=0,
header_row_index=0,
target_row_index=1,
debug=True,
)Updating a vertical table
tables.update_vertical(
update_contents,
table_index=2,
key_col_index=0,
value_col_index=1,
allow_new_keys=False,
debug=True,
)With allow_new_keys=True, keys that do not exist are added as new rows.
Reading values
horizontal_values = tables.get_horizontal(table_index=0)
vertical_values = tables.get_vertical(table_index=2, value_col_index=1)Clearing a horizontal table
When the number of columns in update_contents changes, for example, you can first reset the table to the header row and one empty value row, then update it.
tables.clear_horizontal(table_index=0, header_row_index=0)
tables.update_horizontal(update_contents, table_index=0, header_row_index=0, target_row_index=1)Making a table collapsible
tables.set_collapsible(
table_index=0,
summary_text="Measurement conditions",
open=False,
)Pitfalls
- Table updates depend on the order of tables in the body, the header row, the target row, and the positions of the key / value columns. If you change the template structure, check
table_index,header_row_index,target_row_index,key_col_index, andvalue_col_index.
Steps / checklists
The intended workflow is to prepare Steps in an Experiment template, copy them into Experiments created with elab.experiments.init(..., copy_template_steps=True) (the default), and then use the Experiment's Steps to track progress.
steps = elab.experiments.entry(experiment_id).steps
steps_df = steps.list(debug=True) # list
steps.add("Attach the analysis script", finished=False) # add
steps.set_finished(step_id=1, finished=True) # check
steps.set_finished(step_id=1, finished=False) # uncheck
steps.update(step_id=1, body="Attach the analysis script and result figures") # update the text
steps.set_finished_by_body("analysis script", finished=True) # find by part of the text and checkSteps of Resource / Database items work the same way:
item_steps = elab.items.entry(item_id).steps
item_steps.list(debug=True)
item_steps.add("Check the sample information")Also available: steps.toggle(step_id) (invert the check), steps.delete(step_id), steps.replace(step_bodies) (replace the Steps with the given list of texts), steps.copy_to(target_entity_id) (copy to another entry), and steps.raw().
Next: 10. MaiML export.