Is it possible to clone figure object to put it in several html documents?


I am trying to insert some subplots that are common in multiple html files, but I get the error:

Models must be owned by only a single document

I tried to use copy.deepcopy and serializing-deserializing json but no luck


I solved it by removing the row with constant plots every time after save)) Below is the code block, I was getting rid of the last (third ) row:

  doc = layout([
    ], sizing_mode="stretch_both", max_height=800)


    # remove the all score plots from the doc

That’s one way. Another method would be to encapsulate the creation of the plots that need to go in multiple docs inside a function so that it’s easy to just create new ones.

You could use the somewhat obscure OutputDocumentFor constext manager.

FWIW there is a private _clone method on models:

I am not sure why this is private except perhaps that no one has ever asked about this before. You might open a GitHub issue to open a discussion about making this public.