The viewer's history, live: notebook turns and what changed
cellucid_turn.RdA notebook turn makes every action sent while its code runs one turn of the viewer's history: the State panel shows them as one group, and they are undone together. Turns do not nest.
The viewer tells every change of its history as a history_changed
event: cellucid_last_history_change() is the latest, and
cellucid_on(viewer, "history_changed", handler) runs code on
each. The history is read as a session
(cellucid_request_session(), then
cellucid_trackers()) and changed through its actions, the
generated cellucid_history_*() functions
(cellucid_history_undo(), cellucid_history_jump(),
cellucid_history_note_add(), ...), as the State panel and
agents change it. cellucid-python's viewer.turn() and
viewer.history are the same calls.
Arguments
- viewer
What
cellucid_view()orcellucid_serve()returned.- label
What the turn does, in a few words (
"Normalise and cluster"): the State panel shows it as the turn's name. White space is collapsed.- code
The code to run inside the turn: every action it sends is one step of the turn.
Value
cellucid_turn(): the turn's id ("r-" and 12 hexadecimal
digits), invisibly, for cellucid_history_turn_undo() or a note
on the turn (cellucid_history_note_add(viewer, target =
list(turn = id), text = ...)).
cellucid_last_history_change(): the latest change of the viewer's
history it told, list(kind, tracker, head, step, branch), or
NULL before the first: kind is "step" (a step
recorded: step is its id), "moved" (the step shown moved:
undo, redo, a jump, a branch switched to), "edited" (a note, a
bookmark, a branch renamed, locked, archived or deleted), "tracker"
(a tracker started, used, renamed or removed) or "loaded" (a session
loaded); tracker the tracker in use, head the step shown and
branch the active branch.
Examples
if (FALSE) { # \dontrun{
v <- cellucid_view(sce)
turn <- cellucid_turn(v, "Mark the T cells", {
cellucid_color_by(v, field = list(source = "obs", key = "cell_type"))
cellucid_highlight_cells(v, which(sce$cell_type == "T cell"))
})
cellucid_history_note_add(v, target = list(turn = turn), text = "T cells by cell_type.")
cellucid_on(v, "history_changed", function(change) message(change$kind, " ", change$head))
cellucid_last_history_change(v)
cellucid_history_turn_undo(v, turn = turn)
} # }