trrackpy¶
Track the state of anywidget widgets.
Click the counter, undo, and click again:
This is the code that runs above:
import anywidget
import traitlets
from trrack_widget import Trrackable
class Counter(anywidget.AnyWidget):
_esm = """
export default {
render({ model, el }) {
const button = document.createElement("button");
const draw = () => (button.textContent = `count: ${model.get("count")}`);
button.onclick = () => {
model.set("count", model.get("count") + 1);
model.save_changes();
};
model.on("change:count", draw);
draw();
el.append(button);
},
};
"""
count = traitlets.Int(0).tag(sync=True)
Trrackable(Counter())
Persistedsaves a widget's state and restores it the next time it loads.Trrackablerecords every change as a history you can navigate.- A store decides where the state lives: a file, a database, the URL. Write your own with two methods.
Where to start¶
- Install the package.
- Follow the Quickstart.
- Read the guides for Persisted and Trrackable.
- Run an example notebook.