Automatic update of scale of figure after loading it from json

Hello!
Explain me please how it works and how it could be fixed.

I have a dashboard for data analysis. It doesn’t run server, all callbacks are writed in JavaScript. There I can save plots (to the last tab) which I’ve created after filtering df and add another info to them (like commentaries which insights I’ve found in them).

The thing I needed is to save my “progress”. In other words, I run dashboard, do some researches saving plots and adding commentaries to them. Then I save it into .json-file to keep all the info and then I want to load it again in Jupyter Notebook and continue working with it.
p-himik helped me with that here (thank you very much):

Everything works, all the info remains there, but it has one issue - it doesn’t auto-scale figure where my plot is like it was doing on the dashboard which I’ve saved then. I’m attaching .gif which demonstrates that - https://gifyu.com/image/dAbR.
I’ve tried to set y_range manually, to change follow-parameters, but it doesn’t help. It seems it isn’t related to y_range.

Thanks in advance!

I’ve tried to set y_range manually, to change follow-parameters, but it doesn’t help

Explicitly setting the range values overrides auto-ranging, so that would do the opposite of you want. I don’t know if what you want is currently supported. This is an unusual mode of usage that no one has ever asked for. What would help investigate is a minimal, complete reproducer. With emphasis on minimal: I am suggesting to construct a complete toy example that is much simple than what it is in the video, that still demonstrates the behaviour.

I’ve tried to do it.
The layout - https://pastebin.com/YMSu4Vy4.
Function to load .json-file - https://pastebin.com/MLUydxXk.

I’m sorry, but the 2nd one doesn’t work like it should - it accepts file, but doesn’t show anything. It was happenning to me sometimes before and I still couldn’t figure out why it doesn’t render sometimes. By now, it renders my whole dashboard, but shows nothing when I upload this mini-sample. I hope you could help me with it too. After that it will be possible to reproduce that mis-updating of figure.

Thank you!

Upd1. Fixed and made simplier the 1st code. Now the load-function (2nd code) works properly. The behaviour of non-updating figure after saving and load it is reproducible.

I am unable to get the saved JSON output to load in a Python interpreter for inspection. The entire file is one giant quoted string, which does not seem correct.

In any case, digging into the file by hand it’s evident that the one DataRange1d that is in it has start and end set to explicit numerical values, which is the proximate cause for why the range does not update. I’m not sure offhand what to suggest except digging through the re-constituted document to find the range object, and set its start and end properties back to null (which signifies auto-ranging should occur) before embedding it.

GIF - https://gifyu.com/image/dAYj.
But what happens to the document, that after save/load operation it loses exactly this capability to auto-range the figure? All the rest works as it should.

My .json-file from the video - https://yadi.sk/d/6sbeDBz9_xRsXw. It seems, there are all the properties of the document listed.

I’ll try the thing with DataRange1d.

Okay, it works now.

The workaround was to set manually y_range-parameter for figure (where plot shows) upon creating it and then keep changing fig.y_range.start and fig.y_range.end in callbacks manually depending on min and max values of aggregated array respectively (which provide info for “top” of the plot).
It seems that this feature is applied by default but for some reason it doesn’t appear in .json-file when you save the document, that’s why it doesn’t restore on load.

By the way, before manually setting y_range it worked this way: 1) figure creating; 2) lag about 1-1,5 seconds to adjust figure (for example, if y-ticks were 1,2,3 and had enough place to show there and now there are 1000, 2000, 3000, figure auto-adjust plot’s size so that y-ticks wouldn’t be out of the layout), 3) applying hover-info.
Now it works this way: 1) lag for about 1-1,5 seconds; 2) already fitted figure creating with hover-info already applied.

Is there any sense in setting default y_range for each figure if it wasn’t stated by user manually? In order not to lose this property upon saving document.