I'm looking for a way to programatically change the contents of a jupyterlab cell after it has been run as a way to "lock" it.
For my specific use-case, my cell essentially looks like
curr_id = get_curr_id()
data = load_data(curr_id)
When I run this, get_curr_id() accesses a database and finds the most recent added dataset. After the cell is run once I want to "lock" this id to the cell, so that even if new data is added to the database, this cell will still reference the original dataset it first saw. I thought the easiest way to do this would be to programatically replace "curr_id = get_curr_id()" with the returned curr_id, but am not sure how to proceed.
As more context, the database I am pulling from has new entries added every ~30 min. My typical workflow is to run a cell like above and analyze it. Then ~30 min later copy that same cell and run it again to analyze the new data that came in. However, if I now go back to the first cell, re-running it will now load the newest data, instead of the original data it found.
Solution: In any case, I found a solution using ipython, linked below
get_curr_id(). For what I understand you want that the first time it's called it gets the data from the DB and freezes it, so the next time it will get the same value as before. So save the frozen value into a file, or create a new table in your DB where you store this value.