-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
898 save app state #907
898 save app state #907
Conversation
Hey, well done with |
Thanks @m7pr 🙂 I have done some more research into how one can interfere with the reactive cycle. I wanted to manually manipulate invalidation flags but I didn't find a way. I tried dynamically injecting JS that would ignore some events on some elements, the assumption was that I could kill part of the reactivity for the duration of the update, but in the end it has to be brought back up in another flush cycle. I give up. The cyclical clicks are the bes I can do. To mitigate the side effect I tried to add a loader that will obscure the plot until all updates are complete but it keeps popping up anyway. I will spend a little more time to make sure saving and loading works properly and then open the PR for review. |
Update: saving and loading works ok in tests but I have not incorporated it into the module fully yet, meaning one can save but not load (much like filter snapshots). We should consider whether we want to save inputs and filter state separately or together, or let the user decide. The latter two would require rebuilding the modules so I would like to discuss this issue before getting into it. |
Code Coverage Summary
Diff against main
Results for commit: c2e1d66 Minimum allowed coverage is ♻️ This comment has been updated with latest results |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we are trying redo what shiny offers with bookmarking. There is a nice option to save states on the server and reuse them with url like https://gallery.shinyapps.io/bookmark-saved/?_state_id_=<STATE ID>
. Maybe we can store there selected inputs plus reactiveValues
(eg. slices_global).
In the "ancient" teal we had bookmarking which handled filter-states
Line 190 in 8240395
datasets$restore_state_from_bookmark(saved_datasets_state) |
Maybe we can address it in a similar way?
Signed-off-by: Aleksander Chlebowski <[email protected]>
Closes #898
Prototype for saving and restoring app state, i.e. selection state of all inputs in app. When complete, can be easily combined with saving filter state.
The problem
In essence, everything comes down to two actions: 1) find state of all inputs in the app, and 2) set state of all inputs in the app. Once we have the state in hand, saving and retrieving it is trivial.
Ad 1) One simply has to go through the
input
object. Modules slightly complicate things as things are namespaced and separated but that is solved by finding the master session object (the one for the app, not for individual modules) and working from there.Ad 2) This is not hard in principle as one can set the state of any input with
session$sendInputMessage
, using the master session object and namespaced input ids. However...The issue
Inputs in
data_extract_spec
s are hierarchical, meaning given a dataset, one first selects a column and then a value from that column. The value input is created in response to selecting a column value. Now, when one wants to restore input states, one will click a button to trigger an observer and within that observersession$sendInputMessage
will be called. This will queue messages that will update all inputs as required but those messages will only be applied after the observer closes. Then, when the higher order input is updated, the lower order input will be reset to default.See the example app below.
So, the nature of the reactive cycle kills the reset process. I tried forcing flushes, I tried calling the update function recursively, at the moment I cannot solve this.The only solution I was able to find is to click the button again and keep clicking it until all inputs are identical to the saved state. This usually takes 2-3 cycles but may potentially take more if the input hierarchy is more than two deep. I consider this a workaround rather than a mature solution. Repeated clicks translate to multiple updates of plots, which deteriorates user experience. I am aware.
You can try the solution by running a
teal
app (on this branch). Repeated clicks in the module are done programmatically but you have to click manually in the example app.Notes
I packaged it into a module styled after (filter) snapshot manager to allow testing in teal apps. This need not be the final solution.
Saving and loading may still have some bugs (probably does), I don't want to get into minutiae before the major issues are solved.Simple testing app