@@ -562,6 +562,8 @@ def _reset_reactives(self) -> None:
562562 self ._updated_data .unset ()
563563
564564 def _init_reactives (self ) -> None :
565+ from ..bookmark ._restore_state import RestoreState
566+ from ..bookmark ._save_state import BookmarkState
565567
566568 # Init
567569 self ._value = reactive .Value (None )
@@ -588,6 +590,57 @@ async def _():
588590 # It currently is, as `@reactive.event()` is being used
589591 await self ._attempt_update_cell_style ()
590592
593+ def bookmark_cell_patch_id () -> str :
594+ return f"{ self .output_id } --cell_patch_map"
595+
596+ def bookmark_data_id () -> str :
597+ return f"{ self .output_id } --data"
598+
599+ @self ._get_session ().bookmark .on_bookmark
600+ def _ (state : BookmarkState ):
601+ cell_patch_map = self ._cell_patch_map ()
602+ if cell_patch_map :
603+ cell_patch_id_val = bookmark_cell_patch_id ()
604+ if cell_patch_id_val in state .values :
605+ raise RuntimeError (
606+ f"Bookmark state already contains a value for { cell_patch_id_val } . Please use a different ID."
607+ )
608+ state .values [cell_patch_id_val ] = cell_patch_map
609+
610+ updated_data = self ._updated_data ()
611+ if updated_data :
612+ # TODO-barret-render.data_frame; Handle restoring updated data
613+ # Related: Restoring Chat UI: https://github.com/posit-dev/py-shiny/issues/1952
614+ raise RuntimeError (
615+ "Bookmarking an updated data frame is not supported."
616+ )
617+
618+ @self ._get_session ().bookmark .on_restore
619+ def _ (state : RestoreState ):
620+ if state .input [f"{ self .output_id } _cell_selection" ]:
621+ self .update_cell_selection (
622+ state .input [f"{ self .output_id } _cell_selection" ]
623+ )
624+ if state .input [f"{ self .output_id } _column_sort" ]:
625+ self .update_sort (state .input [f"{ self .output_id } _column_sort" ])
626+ if state .input [f"{ self .output_id } _column_filter" ]:
627+ self .update_filter (state .input [f"{ self .output_id } _column_filter" ])
628+ if state .input [f"{ self .output_id } _cell_selection" ]:
629+ self .update_cell_selection (
630+ state .input [f"{ self .output_id } _cell_selection" ]
631+ )
632+ if state .input [f"{ self .output_id } _data_view_rows" ]:
633+
634+ cell_patch_map = state .values .get (bookmark_cell_patch_id (), None )
635+ if cell_patch_map :
636+ self ._cell_patch_map .set (cell_patch_map )
637+ self ._updated_data .set (self ._nw_data_to_original_type (self ._nw_data ()))
638+
639+ updated_data = state .values .get (bookmark_data_id (), None )
640+ if updated_data :
641+ # TODO-barret-render.data_frame; Handle restoring updated data
642+ raise RuntimeError ("Restoring an updated data frame is not supported." )
643+
591644 def _get_session (self ) -> Session :
592645 if self ._session is None :
593646 raise RuntimeError (
0 commit comments