Serving a custom bokeh document

Hi there,

I read that bokeh documents are the unit at which bokeh plots are serialized. How then can I configure the server to provide a custom bokeh document?

The examples that I found would either use curdoc or a bokeh application with a FunctionHandler. Is there a path from a custom document to a server?

I have also asked this question on SO: https://stackoverflow.com/questions/55747236/how-can-i-serve-a-bokeh-document-loaded-from-a-json

Best regards,

Niklas

Hi,

A Bokeh Document is a very specific thing, it is a data structure that handles communicating all your Bokeh objects (i.e. Plots, data sources, tools, etc) between Python and the browser. In particular, it's not an "HTML Document" I can't think of any reason for anyone to ever need or want to subclass or customize Boeh's Document data structure. Can you elaborate on what you are actually trying to accomplish, and why you think you need a custom version of Document to do it?

Thanks,

Bryan

···

On Apr 18, 2019, at 9:11 AM, Niklas <[email protected]> wrote:

Hi there,

I read that bokeh documents are the unit at which bokeh plots are serialized. How then can I configure the server to provide a custom bokeh document?

The examples that I found would either use curdoc or a bokeh application with a FunctionHandler. Is there a path from a custom document to a server?

I have also asked this question on SO: How can I serve a Bokeh document loaded from a JSON? - Stack Overflow

Best regards,
Niklas

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/989b2e66-f78a-4b6c-9bef-37489f339ada%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Byran,

maybe the word ‘custom’ is misleading. I want to load/store a bokeh document from/to a json file. So far I could not find a method to display the document with the bokeh server.

In the bokeh documentation I found two methods that describe how to display plots with bokeh: (a) by adding plots to curdoc() [1] or (b) by using a FunctionHandler [2]

But they do not help me with serving a document created by deserializing a JSON (from_json or from_json_string) [3].

Cheers,

Niklas

[1] https://bokeh.pydata.org/en/latest/docs/user_guide/server.html

[2] https://bokeh.pydata.org/en/latest/docs/reference/application/handlers/function.html

[3] https://bokeh.pydata.org/en/latest/docs/reference/document.html

···

Am Donnerstag, 18. April 2019 20:27:45 UTC+2 schrieb Bryan Van de Ven:

Hi,

A Bokeh Document is a very specific thing, it is a data structure that handles communicating all your Bokeh objects (i.e. Plots, data sources, tools, etc) between Python and the browser. In particular, it’s not an “HTML Document” I can’t think of any reason for anyone to ever need or want to subclass or customize Boeh’s Document data structure. Can you elaborate on what you are actually trying to accomplish, and why you think you need a custom version of Document to do it?

Thanks,

Bryan

On Apr 18, 2019, at 9:11 AM, Niklas [email protected] wrote:

Hi there,

I read that bokeh documents are the unit at which bokeh plots are serialized. How then can I configure the server to provide a custom bokeh document?

The examples that I found would either use curdoc or a bokeh application with a FunctionHandler. Is there a path from a custom document to a server?

I have also asked this question on SO: https://stackoverflow.com/questions/55747236/how-can-i-serve-a-bokeh-document-loaded-from-a-json

Best regards,

Niklas


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/989b2e66-f78a-4b6c-9bef-37489f339ada%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi,

The JSON export/embed functions are only for standalone (non-server) content. There is no supported mechanism for JSON-only export of a Bokeh server app.

Thanks,

Bryan

···

On Apr 23, 2019, at 12:21 AM, [email protected] wrote:

Hi Byran,

maybe the word 'custom' is misleading. I want to load/store a bokeh document from/to a json file. So far I could not find a method to display the document with the bokeh server.

In the bokeh documentation I found two methods that describe how to display plots with bokeh: (a) by adding plots to _curdoc()_ [1] or (b) by using a FunctionHandler [2]

But they do not help me with serving a document created by deserializing a JSON (from_json or from_json_string) [3].

Cheers,
Niklas

[1] Bokeh server — Bokeh 3.3.2 Documentation
[2] bokeh.application.handlers.function — Bokeh 3.3.2 Documentation
[3] bokeh.document — Bokeh 3.3.2 Documentation

Am Donnerstag, 18. April 2019 20:27:45 UTC+2 schrieb Bryan Van de Ven:
Hi,

A Bokeh Document is a very specific thing, it is a data structure that handles communicating all your Bokeh objects (i.e. Plots, data sources, tools, etc) between Python and the browser. In particular, it's not an "HTML Document" I can't think of any reason for anyone to ever need or want to subclass or customize Boeh's Document data structure. Can you elaborate on what you are actually trying to accomplish, and why you think you need a custom version of Document to do it?

Thanks,

Bryan

> On Apr 18, 2019, at 9:11 AM, Niklas <[email protected]> wrote:
>
> Hi there,
>
> I read that bokeh documents are the unit at which bokeh plots are serialized. How then can I configure the server to provide a custom bokeh document?
>
> The examples that I found would either use curdoc or a bokeh application with a FunctionHandler. Is there a path from a custom document to a server?
>
> I have also asked this question on SO: How can I serve a Bokeh document loaded from a JSON? - Stack Overflow
>
> Best regards,
> Niklas
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bo...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/989b2e66-f78a-4b6c-9bef-37489f339ada%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/9c93089f-c3e6-4214-947c-39b39349b1e7%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Byran,

thank you for taking the time :). I am not 100% sure that we are speaking about the same issue. Please confirm whether I understand your point correctly:

My understanding was:

  • json_dict = Document.to_json() serializes the state of a document
  • doc = Document.from_json(json_dict) deserializes the state again.
  • There should be a method to serve the deserialized document. (e.g. set_curdoc(doc))
  • The methods that I found where unsuitable, because they are based on changing an existing document:
  • by changing curdoc()
  • by changing a document returned to the callback of the FunctionHandler (e.g. make_doc)

I understand that you are saying:

  • The Document.to_json() serializes only the static part of the document
  • This json object cannot be loaded into a new document and visualized either via the bokeh serve program or a bokeh.application.application.Application or any other method.

If I get this correctly, then this is very confusing. The documentation states that the method to_json() “Convert this document to a JSON object”, which is then wrong, right? It is only a partial conversion. At least it should include a warning.

Cheers,

Niklas

···

Am Freitag, 26. April 2019 07:34:18 UTC+2 schrieb Bryan Van de Ven:

Hi,

The JSON export/embed functions are only for standalone (non-server) content. There is no supported mechanism for JSON-only export of a Bokeh server app.

Thanks,

Bryan

On Apr 23, 2019, at 12:21 AM, [email protected] wrote:

Hi Byran,

maybe the word ‘custom’ is misleading. I want to load/store a bokeh document from/to a json file. So far I could not find a method to display the document with the bokeh server.

In the bokeh documentation I found two methods that describe how to display plots with bokeh: (a) by adding plots to curdoc() [1] or (b) by using a FunctionHandler [2]

But they do not help me with serving a document created by deserializing a JSON (from_json or from_json_string) [3].

Cheers,

Niklas

[1] https://bokeh.pydata.org/en/latest/docs/user_guide/server.html

[2] https://bokeh.pydata.org/en/latest/docs/reference/application/handlers/function.html

[3] https://bokeh.pydata.org/en/latest/docs/reference/document.html

Am Donnerstag, 18. April 2019 20:27:45 UTC+2 schrieb Bryan Van de Ven:

Hi,

A Bokeh Document is a very specific thing, it is a data structure that handles communicating all your Bokeh objects (i.e. Plots, data sources, tools, etc) between Python and the browser. In particular, it’s not an “HTML Document” I can’t think of any reason for anyone to ever need or want to subclass or customize Boeh’s Document data structure. Can you elaborate on what you are actually trying to accomplish, and why you think you need a custom version of Document to do it?

Thanks,

Bryan

On Apr 18, 2019, at 9:11 AM, Niklas [email protected] wrote:

Hi there,

I read that bokeh documents are the unit at which bokeh plots are serialized. How then can I configure the server to provide a custom bokeh document?

The examples that I found would either use curdoc or a bokeh application with a FunctionHandler. Is there a path from a custom document to a server?

I have also asked this question on SO: https://stackoverflow.com/questions/55747236/how-can-i-serve-a-bokeh-document-loaded-from-a-json

Best regards,
Niklas


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/989b2e66-f78a-4b6c-9bef-37489f339ada%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/9c93089f-c3e6-4214-947c-39b39349b1e7%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi,

TLDR; to work with the server expects you need to be able to mutate an existing document, not create a new one.

I think the documentation is correct, because .to_json does serialize a Document to JSON, and .from_json does deserialize JSON into a *new* Document. It's the *new* part that is tripping you up. Heres' why:

A running Bokeh server app comprises a Document inside a session. So if you want to serve a new document, it also needs to be available for a session to use somehow. We provide mechanisms for sessions to obtain the Documents they should use, in the form of "handlers", i.e a script or notebook handler executes a file that builds a document for the session. Or a function handler executes a function handler to build the document for the session. But the key thing to note here: the server always create a *blank* document itself (creating a new document for a session is its responsibility), and the lets the handlers update/modify that document (rather than return a new one), before passing it to the session. This affords the possibility of multiple handlers being used to build up a single document.

So .from_json does what is advertised (creates a new doc from json), but that is not useful for the task of serving the document, which requires updating an existing document, not creating a new one yourself.

If you want some other mechanism for populating documents for sessions, then what you want is to create a Handler subclass, that does whatever it needs to do to build a document the way you want. e.g if you want to modify the server-created document with from some serialized JSON, then I think you could write a JSONHandler that does just that. But reminder: creating a *new* document (i.e. what .from_json does) is not helpful here because the server always serves the document that it creates. You need to be able to *modify* that existing document (hence the handler method "modify_doc'). Something like this:

  def modify_doc(self, doc):
     my_json = json.load(...)
       doc.replace_with_json(my_json)

The "replace_with_json" is similar to "from_json" except that it destructively overwrites the current doc instead of making a new one. That's the piece you were missing. (Untested, but should be approximately correct.)

Thanks,

Bryan

···

On Apr 26, 2019, at 4:52 AM, [email protected] wrote:

Hi Byran,

thank you for taking the time :). I am not 100% sure that we are speaking about the same issue. Please confirm whether I understand your point correctly:

My understanding was:
  • json_dict = Document.to_json() serializes the state of a document
  • doc = Document.from_json(json_dict) deserializes the state again.
  • There should be a method to serve the deserialized document. (e.g. set_curdoc(doc))
  • The methods that I found where unsuitable, because they are based on changing an existing document:
    • by changing curdoc()
    • by changing a document returned to the callback of the FunctionHandler (e.g. make_doc)
I understand that you are saying:
  • The Document.to_json() serializes only the static part of the document
  • This json object cannot be loaded into a new document and visualized either via the bokeh serve program or a bokeh.application.application.Application or any other method.

If I get this correctly, then this is very confusing. The documentation states that the method to_json() "Convert this document to a JSON object", which is then wrong, right? It is only a partial conversion. At least it should include a warning.

Cheers,
Niklas

Am Freitag, 26. April 2019 07:34:18 UTC+2 schrieb Bryan Van de Ven:
Hi,

The JSON export/embed functions are only for standalone (non-server) content. There is no supported mechanism for JSON-only export of a Bokeh server app.

Thanks,

Bryan

> On Apr 23, 2019, at 12:21 AM, meta...@gmail.com wrote:
>
> Hi Byran,
>
> maybe the word 'custom' is misleading. I want to load/store a bokeh document from/to a json file. So far I could not find a method to display the document with the bokeh server.
>
> In the bokeh documentation I found two methods that describe how to display plots with bokeh: (a) by adding plots to _curdoc()_ [1] or (b) by using a FunctionHandler [2]
>
> But they do not help me with serving a document created by deserializing a JSON (from_json or from_json_string) [3].
>
> Cheers,
> Niklas
>
> [1] Bokeh server — Bokeh 3.3.2 Documentation
> [2] bokeh.application.handlers.function — Bokeh 3.3.2 Documentation
> [3] bokeh.document — Bokeh 3.3.2 Documentation
>
> Am Donnerstag, 18. April 2019 20:27:45 UTC+2 schrieb Bryan Van de Ven:
> Hi,
>
> A Bokeh Document is a very specific thing, it is a data structure that handles communicating all your Bokeh objects (i.e. Plots, data sources, tools, etc) between Python and the browser. In particular, it's not an "HTML Document" I can't think of any reason for anyone to ever need or want to subclass or customize Boeh's Document data structure. Can you elaborate on what you are actually trying to accomplish, and why you think you need a custom version of Document to do it?
>
> Thanks,
>
> Bryan
>
> > On Apr 18, 2019, at 9:11 AM, Niklas <[email protected]> wrote:
> >
> > Hi there,
> >
> > I read that bokeh documents are the unit at which bokeh plots are serialized. How then can I configure the server to provide a custom bokeh document?
> >
> > The examples that I found would either use curdoc or a bokeh application with a FunctionHandler. Is there a path from a custom document to a server?
> >
> > I have also asked this question on SO: How can I serve a Bokeh document loaded from a JSON? - Stack Overflow
> >
> > Best regards,
> > Niklas
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to bo...@continuum.io.
> > To post to this group, send email to bo...@continuum.io.
> > To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/989b2e66-f78a-4b6c-9bef-37489f339ada%40continuum.io\.
> > For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bo...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/9c93089f-c3e6-4214-947c-39b39349b1e7%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e7111a4b-7185-4bc1-8f12-0ced927f6c26%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hello Bryan,

thanks for your time, I get it now! The replace_with_json method works. It only works with the static content, but that is what you already mentioned. Case closed ;-).

Best regards,

Niklas

PS: I just realized I misspelled your name in my last posts. Sorry…

···

Am Freitag, 26. April 2019 18:06:46 UTC+2 schrieb Bryan Van de Ven:

Hi,

TLDR; to work with the server expects you need to be able to mutate an existing document, not create a new one.

I think the documentation is correct, because .to_json does serialize a Document to JSON, and .from_json does deserialize JSON into a new Document. It’s the new part that is tripping you up. Heres’ why:

A running Bokeh server app comprises a Document inside a session. So if you want to serve a new document, it also needs to be available for a session to use somehow. We provide mechanisms for sessions to obtain the Documents they should use, in the form of “handlers”, i.e a script or notebook handler executes a file that builds a document for the session. Or a function handler executes a function handler to build the document for the session. But the key thing to note here: the server always create a blank document itself (creating a new document for a session is its responsibility), and the lets the handlers update/modify that document (rather than return a new one), before passing it to the session. This affords the possibility of multiple handlers being used to build up a single document.

So .from_json does what is advertised (creates a new doc from json), but that is not useful for the task of serving the document, which requires updating an existing document, not creating a new one yourself.

If you want some other mechanism for populating documents for sessions, then what you want is to create a Handler subclass, that does whatever it needs to do to build a document the way you want. e.g if you want to modify the server-created document with from some serialized JSON, then I think you could write a JSONHandler that does just that. But reminder: creating a new document (i.e. what .from_json does) is not helpful here because the server always serves the document that it creates. You need to be able to modify that existing document (hence the handler method "modify_doc’). Something like this:

    def modify_doc(self, doc):

             my_json = json.load(...)

               doc.replace_with_json(my_json)

The “replace_with_json” is similar to “from_json” except that it destructively overwrites the current doc instead of making a new one. That’s the piece you were missing. (Untested, but should be approximately correct.)

Thanks,

Bryan

On Apr 26, 2019, at 4:52 AM, [email protected] wrote:

Hi Byran,

thank you for taking the time :). I am not 100% sure that we are speaking about the same issue. Please confirm whether I understand your point correctly:

My understanding was:

    • json_dict = Document.to_json() serializes the state of a document
    • doc = Document.from_json(json_dict) deserializes the state again.
    • There should be a method to serve the deserialized document. (e.g. set_curdoc(doc))
    • The methods that I found where unsuitable, because they are based on changing an existing document:
            • by changing curdoc()
            • by changing a document returned to the callback of the FunctionHandler (e.g. make_doc)

I understand that you are saying:

    • The Document.to_json() serializes only the static part of the document
    • This json object cannot be loaded into a new document and visualized either via the bokeh serve program or a bokeh.application.application.Application or any other method.

If I get this correctly, then this is very confusing. The documentation states that the method to_json() “Convert this document to a JSON object”, which is then wrong, right? It is only a partial conversion. At least it should include a warning.

Cheers,

Niklas

Am Freitag, 26. April 2019 07:34:18 UTC+2 schrieb Bryan Van de Ven:

Hi,

The JSON export/embed functions are only for standalone (non-server) content. There is no supported mechanism for JSON-only export of a Bokeh server app.

Thanks,

Bryan

On Apr 23, 2019, at 12:21 AM, [email protected] wrote:

Hi Byran,

maybe the word ‘custom’ is misleading. I want to load/store a bokeh document from/to a json file. So far I could not find a method to display the document with the bokeh server.

In the bokeh documentation I found two methods that describe how to display plots with bokeh: (a) by adding plots to curdoc() [1] or (b) by using a FunctionHandler [2]

But they do not help me with serving a document created by deserializing a JSON (from_json or from_json_string) [3].

Cheers,
Niklas

[1] https://bokeh.pydata.org/en/latest/docs/user_guide/server.html

[2] https://bokeh.pydata.org/en/latest/docs/reference/application/handlers/function.html

[3] https://bokeh.pydata.org/en/latest/docs/reference/document.html

Am Donnerstag, 18. April 2019 20:27:45 UTC+2 schrieb Bryan Van de Ven:
Hi,

A Bokeh Document is a very specific thing, it is a data structure that handles communicating all your Bokeh objects (i.e. Plots, data sources, tools, etc) between Python and the browser. In particular, it’s not an “HTML Document” I can’t think of any reason for anyone to ever need or want to subclass or customize Boeh’s Document data structure. Can you elaborate on what you are actually trying to accomplish, and why you think you need a custom version of Document to do it?

Thanks,

Bryan

On Apr 18, 2019, at 9:11 AM, Niklas [email protected] wrote:

Hi there,

I read that bokeh documents are the unit at which bokeh plots are serialized. How then can I configure the server to provide a custom bokeh document?

The examples that I found would either use curdoc or a bokeh application with a FunctionHandler. Is there a path from a custom document to a server?

I have also asked this question on SO: https://stackoverflow.com/questions/55747236/how-can-i-serve-a-bokeh-document-loaded-from-a-json

Best regards,
Niklas


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/989b2e66-f78a-4b6c-9bef-37489f339ada%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/9c93089f-c3e6-4214-947c-39b39349b1e7%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e7111a4b-7185-4bc1-8f12-0ced927f6c26%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi,

I'm glad to hear it is working. Just one final note: It's not really accurate to say this only works with static content. More precisely, typically its you yourself who explicitly creates a Slider, say, so it's easy for you to add a callback that slider, because you have a reference to it. You could still technically do that here, it's just that you didn't instantiate the Bokeh models yourself, so you don't have an easy handle to them. But they exist, and if you dig around the Document you updated after you call "replace_with_json", you can obtain real (Python) Bokeh objects that you could update or add callbacks to, just like with any model you created yourself. "Document._all_models" is one place you could look. There are also some public "query" methods on Document that might allow you to find models without using the private attribute.

Thanks,

Bryan

···

On Apr 28, 2019, at 2:16 AM, [email protected] wrote:

Hello Bryan,

thanks for your time, I get it now! The replace_with_json method works. It only works with the static content, but that is what you already mentioned. Case closed ;-).

Best regards,
Niklas

PS: I just realized I misspelled your name in my last posts. Sorry...

Am Freitag, 26. April 2019 18:06:46 UTC+2 schrieb Bryan Van de Ven:

Hi,

TLDR; to work with the server expects you need to be able to mutate an existing document, not create a new one.

I think the documentation is correct, because .to_json does serialize a Document to JSON, and .from_json does deserialize JSON into a *new* Document. It's the *new* part that is tripping you up. Heres' why:

A running Bokeh server app comprises a Document inside a session. So if you want to serve a new document, it also needs to be available for a session to use somehow. We provide mechanisms for sessions to obtain the Documents they should use, in the form of "handlers", i.e a script or notebook handler executes a file that builds a document for the session. Or a function handler executes a function handler to build the document for the session. But the key thing to note here: the server always create a *blank* document itself (creating a new document for a session is its responsibility), and the lets the handlers update/modify that document (rather than return a new one), before passing it to the session. This affords the possibility of multiple handlers being used to build up a single document.

So .from_json does what is advertised (creates a new doc from json), but that is not useful for the task of serving the document, which requires updating an existing document, not creating a new one yourself.

If you want some other mechanism for populating documents for sessions, then what you want is to create a Handler subclass, that does whatever it needs to do to build a document the way you want. e.g if you want to modify the server-created document with from some serialized JSON, then I think you could write a JSONHandler that does just that. But reminder: creating a *new* document (i.e. what .from_json does) is not helpful here because the server always serves the document that it creates. You need to be able to *modify* that existing document (hence the handler method "modify_doc'). Something like this:

        def modify_doc(self, doc):
                 my_json = json.load(...)
                   doc.replace_with_json(my_json)

The "replace_with_json" is similar to "from_json" except that it destructively overwrites the current doc instead of making a new one. That's the piece you were missing. (Untested, but should be approximately correct.)

Thanks,

Bryan

> On Apr 26, 2019, at 4:52 AM, meta...@gmail.com wrote:
>
> Hi Byran,
>
> thank you for taking the time :). I am not 100% sure that we are speaking about the same issue. Please confirm whether I understand your point correctly:
>
> My understanding was:
> • json_dict = Document.to_json() serializes the state of a document
> • doc = Document.from_json(json_dict) deserializes the state again.
> • There should be a method to serve the deserialized document. (e.g. set_curdoc(doc))
> • The methods that I found where unsuitable, because they are based on changing an existing document:
> • by changing curdoc()
> • by changing a document returned to the callback of the FunctionHandler (e.g. make_doc)
> I understand that you are saying:
> • The Document.to_json() serializes only the static part of the document
> • This json object cannot be loaded into a new document and visualized either via the bokeh serve program or a bokeh.application.application.Application or any other method.
>
> If I get this correctly, then this is very confusing. The documentation states that the method to_json() "Convert this document to a JSON object", which is then wrong, right? It is only a partial conversion. At least it should include a warning.
>
> Cheers,
> Niklas
>
> Am Freitag, 26. April 2019 07:34:18 UTC+2 schrieb Bryan Van de Ven:
> Hi,
>
> The JSON export/embed functions are only for standalone (non-server) content. There is no supported mechanism for JSON-only export of a Bokeh server app.
>
> Thanks,
>
> Bryan
>
> > On Apr 23, 2019, at 12:21 AM, meta...@gmail.com wrote:
> >
> > Hi Byran,
> >
> > maybe the word 'custom' is misleading. I want to load/store a bokeh document from/to a json file. So far I could not find a method to display the document with the bokeh server.
> >
> > In the bokeh documentation I found two methods that describe how to display plots with bokeh: (a) by adding plots to _curdoc()_ [1] or (b) by using a FunctionHandler [2]
> >
> > But they do not help me with serving a document created by deserializing a JSON (from_json or from_json_string) [3].
> >
> > Cheers,
> > Niklas
> >
> > [1] Bokeh server — Bokeh 3.3.2 Documentation
> > [2] bokeh.application.handlers.function — Bokeh 3.3.2 Documentation
> > [3] bokeh.document — Bokeh 3.3.2 Documentation
> >
> > Am Donnerstag, 18. April 2019 20:27:45 UTC+2 schrieb Bryan Van de Ven:
> > Hi,
> >
> > A Bokeh Document is a very specific thing, it is a data structure that handles communicating all your Bokeh objects (i.e. Plots, data sources, tools, etc) between Python and the browser. In particular, it's not an "HTML Document" I can't think of any reason for anyone to ever need or want to subclass or customize Boeh's Document data structure. Can you elaborate on what you are actually trying to accomplish, and why you think you need a custom version of Document to do it?
> >
> > Thanks,
> >
> > Bryan
> >
> > > On Apr 18, 2019, at 9:11 AM, Niklas <[email protected]> wrote:
> > >
> > > Hi there,
> > >
> > > I read that bokeh documents are the unit at which bokeh plots are serialized. How then can I configure the server to provide a custom bokeh document?
> > >
> > > The examples that I found would either use curdoc or a bokeh application with a FunctionHandler. Is there a path from a custom document to a server?
> > >
> > > I have also asked this question on SO: How can I serve a Bokeh document loaded from a JSON? - Stack Overflow
> > >
> > > Best regards,
> > > Niklas
> > >
> > > --
> > > You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> > > To unsubscribe from this group and stop receiving emails from it, send an email to bo...@continuum.io.
> > > To post to this group, send email to bo...@continuum.io.
> > > To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/989b2e66-f78a-4b6c-9bef-37489f339ada%40continuum.io\.
> > > For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to bo...@continuum.io.
> > To post to this group, send email to bo...@continuum.io.
> > To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/9c93089f-c3e6-4214-947c-39b39349b1e7%40continuum.io\.
> > For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bo...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e7111a4b-7185-4bc1-8f12-0ced927f6c26%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/59ed0dc0-4321-4a28-bafe-a1d9b243359f%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.