Restore toolbarbutton state on page refresh

I have a toolbar button which is a dropdown. from there user can select an option, according to which some changes are made. On page refresh, the dropdown goes back to its default value, but the changes remain. How can I save the dropdown value so that I can reset to that value on page refresh?

It depends on how persistent and shared you intend it to be:

  • use statedb
    • will persist between browser refreshes, but be lost when leaving by incognito mode, hard refresh, etc.
  • use settings
    • this will persist between different browsers, or even different computers, served by the same jupyter_server, be lost when the server is lost
  • use notebook metadata (if this is about a notebook)
    • this will persist only along with the file
  • use a custom serverextension
    • substantially harder to build and package properly, but could potentially work between multiple users, computers, etc.
1 Like

In my case, the value should be in sync with the kernel. In the onChange part of the dropdown, I do a kernel restart. So what I want is, on a page refresh, or say opening the same page on a different browser, i.e., for a running kernel, the the dropdown value should be correctly reflected. Right now however, if I refresh the page, the dropdown shows a default value, but since the kernel is still running, there is a mis-representation.

Some more details: Based on dropdown value, I am setting some env variables to the kernel. So it is important that I can look at the dropdown and realize which env variables are set.

Yeah, nothing really supports that, today: something like ipylab would work, but it doesn’t currently allow for control of the non-global things (e.g. all the notebooks).

It’s plausible you could do something with the debug adapter protocol, which provides variable inspecting, but I haven’t looked into that part of the codebase much, and it certainly doesn’t work for all kernels, yet.