Upload Data File to Bokeh Server

I’m implementing a data analytics app that allows users to select and upload their data files (e.g., csv or pkl) from local. It seems the current Bokeh library by itself does not support such a tool, and embedding it with Flask or Django may be the only way out. Any ideas?

Hi,

This new example added for 0.12.4 might be of interes:

  https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_embed.py

It shows how to embed a Bokeh server app in a Flask app in a single ".py" file.

Alternatively, Bokeh is extensible, you could write an custom extension to do something like what you describe:

  http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html

Thanks,

Bryan

···

On Jan 11, 2017, at 1:28 PM, Luyu Wang <[email protected]> wrote:

I'm implementing a data analytics app that allows users to select and upload their data files (e.g., csv or pkl) from local. It seems the current Bokeh library by itself does not support such a tool, and embedding it with Flask or Django may be the only way out. Any ideas?

--
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/af7035cc-3ef5-4780-a162-ec1323709b1c%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Awesome!

So if embedded with Flask, can we still use server_lifecycle.py or theme.yaml to control over the Bokeh app?

···

On Wednesday, January 11, 2017 at 3:01:44 PM UTC-5, Bryan Van de ven wrote:

Hi,

This new example added for 0.12.4 might be of interes:

    [https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_embed.py)

It shows how to embed a Bokeh server app in a Flask app in a single “.py” file.

Alternatively, Bokeh is extensible, you could write an custom extension to do something like what you describe:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html](http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html)

Thanks,

Bryan

On Jan 11, 2017, at 1:28 PM, Luyu Wang [email protected] wrote:

I’m implementing a data analytics app that allows users to select and upload their data files (e.g., csv or pkl) from local. It seems the current Bokeh library by itself does not support such a tool, and embedding it with Flask or Django may be the only way out. Any ideas?


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/af7035cc-3ef5-4780-a162-ec1323709b1c%40continuum.io.

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

Hi,

I think right now you'd have to be a bit more explicit. For lifecycle hooks, I think you'd need to create one of these ServerLifeCycleHandler objects:

  https://github.com/bokeh/bokeh/blob/master/bokeh/application/handlers/server_lifecycle.py

And then configure the Application with it. Certainly do-able but I have not had a chance to write up any examples for it yet (but am happy to answer any additional questions).

Same thing for themes, yes definitely can but will need to explicitly create a Theme object. Here is an example that shows how that can be done:

  https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/bar_chart.py

Thanks,

Bryan

···

On Jan 11, 2017, at 3:47 PM, Luyu Wang <[email protected]> wrote:

Awesome!

So if embedded with Flask, can we still use server_lifecycle.py or theme.yaml to control over the Bokeh app?

On Wednesday, January 11, 2017 at 3:01:44 PM UTC-5, Bryan Van de ven wrote:
Hi,

This new example added for 0.12.4 might be of interes:

        https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_embed.py

It shows how to embed a Bokeh server app in a Flask app in a single ".py" file.

Alternatively, Bokeh is extensible, you could write an custom extension to do something like what you describe:

        http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html

Thanks,

Bryan

> On Jan 11, 2017, at 1:28 PM, Luyu Wang <[email protected]> wrote:
>
> I'm implementing a data analytics app that allows users to select and upload their data files (e.g., csv or pkl) from local. It seems the current Bokeh library by itself does not support such a tool, and embedding it with Flask or Django may be the only way out. Any ideas?
>
> --
> 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 bokeh+un...@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/af7035cc-3ef5-4780-a162-ec1323709b1c%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/73b2c0ae-ac74-4255-9267-9310894b0586%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Cool! Thank you Bryan.

···

On Wednesday, January 11, 2017 at 6:17:39 PM UTC-5, Bryan Van de ven wrote:

Hi,

I think right now you’d have to be a bit more explicit. For lifecycle hooks, I think you’d need to create one of these ServerLifeCycleHandler objects:

    [https://github.com/bokeh/bokeh/blob/master/bokeh/application/handlers/server_lifecycle.py](https://github.com/bokeh/bokeh/blob/master/bokeh/application/handlers/server_lifecycle.py)

And then configure the Application with it. Certainly do-able but I have not had a chance to write up any examples for it yet (but am happy to answer any additional questions).

Same thing for themes, yes definitely can but will need to explicitly create a Theme object. Here is an example that shows how that can be done:

    [https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/bar_chart.py](https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/bar_chart.py)

Thanks,

Bryan

On Jan 11, 2017, at 3:47 PM, Luyu Wang [email protected] wrote:

Awesome!

So if embedded with Flask, can we still use server_lifecycle.py or theme.yaml to control over the Bokeh app?

On Wednesday, January 11, 2017 at 3:01:44 PM UTC-5, Bryan Van de ven wrote:

Hi,

This new example added for 0.12.4 might be of interes:

    [https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_embed.py)

It shows how to embed a Bokeh server app in a Flask app in a single “.py” file.

Alternatively, Bokeh is extensible, you could write an custom extension to do something like what you describe:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html](http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html)

Thanks,

Bryan

On Jan 11, 2017, at 1:28 PM, Luyu Wang [email protected] wrote:

I’m implementing a data analytics app that allows users to select and upload their data files (e.g., csv or pkl) from local. It seems the current Bokeh library by itself does not support such a tool, and embedding it with Flask or Django may be the only way out. Any ideas?


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/af7035cc-3ef5-4780-a162-ec1323709b1c%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/73b2c0ae-ac74-4255-9267-9310894b0586%40continuum.io.

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

As a followup, I have successfully write a class to let a Bokeh server see the server_lifecycle.py file when embedding with Flask (should be working with other framework, too). The idea is to re-write the original FunctionHandler to include the ServerLifecycleHandler. In my opinion, the original FunctionHandler is a bit simple. Maybe with time we should make it as good as DirectoryHandler.

Original FunctionHandler:

Modified version:

from future import absolute_import, print_function

from bokeh.application.handlers import Handler, ServerLifecycleHandler

from bokeh.util.callback_manager import _check_callback

class FunctionHandler(Handler):

“”" Run a function which modifies a Document “”"
def init(self, func):
super(FunctionHandler, self).init()
_check_callback(func, (‘doc’,))
self._func = func
self._safe_to_fork = True
path = os.path.abspath(‘./’)
lifecycle = join(path, ‘server_lifecycle.py’)
if exists(lifecycle):
self._lifecycle = lifecycle
self._lifecycle_handler = ServerLifecycleHandler(filename=self._lifecycle, argv=)
def modify_document(self, doc):
self._func(doc)
self._safe_to_fork = False
@property
def safe_to_fork(self):
return self._safe_to_fork
def on_server_loaded(self, server_context):
return self._lifecycle_handler.on_server_loaded(server_context)
def on_server_unloaded(self, server_context):
return self._lifecycle_handler.on_server_unloaded(server_context)
def on_session_created(self, session_context):
return self._lifecycle_handler.on_session_created(session_context)
def on_session_destroyed(self, session_context):
return self._lifecycle_handler.on_session_destroyed(session_context)

···

On Wednesday, January 11, 2017 at 6:37:54 PM UTC-5, Luyu Wang wrote:

Cool! Thank you Bryan.

On Wednesday, January 11, 2017 at 6:17:39 PM UTC-5, Bryan Van de ven wrote:

Hi,

I think right now you’d have to be a bit more explicit. For lifecycle hooks, I think you’d need to create one of these ServerLifeCycleHandler objects:

    [https://github.com/bokeh/bokeh/blob/master/bokeh/application/handlers/server_lifecycle.py](https://github.com/bokeh/bokeh/blob/master/bokeh/application/handlers/server_lifecycle.py)

And then configure the Application with it. Certainly do-able but I have not had a chance to write up any examples for it yet (but am happy to answer any additional questions).

Same thing for themes, yes definitely can but will need to explicitly create a Theme object. Here is an example that shows how that can be done:

    [https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/bar_chart.py](https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/bar_chart.py)

Thanks,

Bryan

On Jan 11, 2017, at 3:47 PM, Luyu Wang [email protected] wrote:

Awesome!

So if embedded with Flask, can we still use server_lifecycle.py or theme.yaml to control over the Bokeh app?

On Wednesday, January 11, 2017 at 3:01:44 PM UTC-5, Bryan Van de ven wrote:

Hi,

This new example added for 0.12.4 might be of interes:

    [https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_embed.py)

It shows how to embed a Bokeh server app in a Flask app in a single “.py” file.

Alternatively, Bokeh is extensible, you could write an custom extension to do something like what you describe:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html](http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html)

Thanks,

Bryan

On Jan 11, 2017, at 1:28 PM, Luyu Wang [email protected] wrote:

I’m implementing a data analytics app that allows users to select and upload their data files (e.g., csv or pkl) from local. It seems the current Bokeh library by itself does not support such a tool, and embedding it with Flask or Django may be the only way out. Any ideas?


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/af7035cc-3ef5-4780-a162-ec1323709b1c%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/73b2c0ae-ac74-4255-9267-9310894b0586%40continuum.io.

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

Hi Luyu,

I am glad to hear you found a solution. I agree that things could be improved to make it easier for Applications with other kinds of handlers to install themes and lifecycle hooks. Can you make a feature request issue on GitHub for this, linking to this thread?

Thanks,

Bryan

···

On Jan 12, 2017, at 2:08 PM, Luyu Wang <[email protected]> wrote:

As a followup, I have successfully write a class to let a Bokeh server see the server_lifecycle.py file when embedding with Flask (should be working with other framework, too). The idea is to re-write the original FunctionHandler to include the ServerLifecycleHandler. In my opinion, the original FunctionHandler is a bit simple. Maybe with time we should make it as good as DirectoryHandler.
Original FunctionHandler:

https://github.com/bokeh/bokeh/blob/9650b109b62d385d372eecc1f9d5a511bf4a3d49/bokeh/application/handlers/function.py

Modified version:

from __future__ import absolute_import, print_function
from bokeh.application.handlers import Handler, ServerLifecycleHandler
from bokeh.util.callback_manager import _check_callback

class FunctionHandler(Handler):
    """ Run a function which modifies a Document """

    def __init__(self, func):
        super(FunctionHandler, self).__init__()
        _check_callback(func, ('doc',))
        self._func = func
        self._safe_to_fork = True

        path = os.path.abspath('./')
        lifecycle = join(path, 'server_lifecycle.py')
        if exists(lifecycle):
            self._lifecycle = lifecycle
            self._lifecycle_handler = ServerLifecycleHandler(filename=self._lifecycle, argv=)

    def modify_document(self, doc):
        self._func(doc)
        self._safe_to_fork = False

    @property
    def safe_to_fork(self):
        return self._safe_to_fork

    def on_server_loaded(self, server_context):
        return self._lifecycle_handler.on_server_loaded(server_context)

    def on_server_unloaded(self, server_context):
        return self._lifecycle_handler.on_server_unloaded(server_context)

    def on_session_created(self, session_context):
        return self._lifecycle_handler.on_session_created(session_context)

    def on_session_destroyed(self, session_context):
        return self._lifecycle_handler.on_session_destroyed(session_context)

On Wednesday, January 11, 2017 at 6:37:54 PM UTC-5, Luyu Wang wrote:
Cool! Thank you Bryan.

On Wednesday, January 11, 2017 at 6:17:39 PM UTC-5, Bryan Van de ven wrote:
Hi,

I think right now you'd have to be a bit more explicit. For lifecycle hooks, I think you'd need to create one of these ServerLifeCycleHandler objects:

        https://github.com/bokeh/bokeh/blob/master/bokeh/application/handlers/server_lifecycle.py

And then configure the Application with it. Certainly do-able but I have not had a chance to write up any examples for it yet (but am happy to answer any additional questions).

Same thing for themes, yes definitely can but will need to explicitly create a Theme object. Here is an example that shows how that can be done:

        https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/bar_chart.py

Thanks,

Bryan

> On Jan 11, 2017, at 3:47 PM, Luyu Wang <[email protected]> wrote:
>
> Awesome!
>
> So if embedded with Flask, can we still use server_lifecycle.py or theme.yaml to control over the Bokeh app?
>
> On Wednesday, January 11, 2017 at 3:01:44 PM UTC-5, Bryan Van de ven wrote:
> Hi,
>
> This new example added for 0.12.4 might be of interes:
>
> https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_embed.py
>
> It shows how to embed a Bokeh server app in a Flask app in a single ".py" file.
>
> Alternatively, Bokeh is extensible, you could write an custom extension to do something like what you describe:
>
> http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html
>
> Thanks,
>
> Bryan
>
> > On Jan 11, 2017, at 1:28 PM, Luyu Wang <[email protected]> wrote:
> >
> > I'm implementing a data analytics app that allows users to select and upload their data files (e.g., csv or pkl) from local. It seems the current Bokeh library by itself does not support such a tool, and embedding it with Flask or Django may be the only way out. Any ideas?
> >
> > --
> > 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 bokeh+un...@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/af7035cc-3ef5-4780-a162-ec1323709b1c%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 bokeh+un...@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/73b2c0ae-ac74-4255-9267-9310894b0586%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/9bb67508-02e4-43f7-9efc-4b8c91234b50%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Bryan,

I’ve made a feature request issue on GitHub (#5728).

Thanks,

Luyu

···

On Friday, January 13, 2017 at 12:24:16 PM UTC-5, Bryan Van de ven wrote:

Hi Luyu,

I am glad to hear you found a solution. I agree that things could be improved to make it easier for Applications with other kinds of handlers to install themes and lifecycle hooks. Can you make a feature request issue on GitHub for this, linking to this thread?

Thanks,

Bryan

On Jan 12, 2017, at 2:08 PM, Luyu Wang [email protected] wrote:

As a followup, I have successfully write a class to let a Bokeh server see the server_lifecycle.py file when embedding with Flask (should be working with other framework, too). The idea is to re-write the original FunctionHandler to include the ServerLifecycleHandler. In my opinion, the original FunctionHandler is a bit simple. Maybe with time we should make it as good as DirectoryHandler.

Original FunctionHandler:

https://github.com/bokeh/bokeh/blob/9650b109b62d385d372eecc1f9d5a511bf4a3d49/bokeh/application/handlers/function.py

Modified version:

from future import absolute_import, print_function

from bokeh.application.handlers import Handler, ServerLifecycleHandler

from bokeh.util.callback_manager import _check_callback

class FunctionHandler(Handler):

""" Run a function which modifies a Document """
def __init__(self, func):
    super(FunctionHandler, self).__init__()
    _check_callback(func, ('doc',))
    self._func = func
    self._safe_to_fork = True
    path = os.path.abspath('./')
    lifecycle = join(path, 'server_lifecycle.py')
    if exists(lifecycle):
        self._lifecycle = lifecycle
        self._lifecycle_handler = ServerLifecycleHandler(filename=self._lifecycle, argv=[])
def modify_document(self, doc):
    self._func(doc)
    self._safe_to_fork = False
@property
def safe_to_fork(self):
    return self._safe_to_fork
def on_server_loaded(self, server_context):
    return self._lifecycle_handler.on_server_loaded(server_context)
def on_server_unloaded(self, server_context):
    return self._lifecycle_handler.on_server_unloaded(server_context)
def on_session_created(self, session_context):
    return self._lifecycle_handler.on_session_created(session_context)
def on_session_destroyed(self, session_context):
    return self._lifecycle_handler.on_session_destroyed(session_context)

On Wednesday, January 11, 2017 at 6:37:54 PM UTC-5, Luyu Wang wrote:

Cool! Thank you Bryan.

On Wednesday, January 11, 2017 at 6:17:39 PM UTC-5, Bryan Van de ven wrote:

Hi,

I think right now you’d have to be a bit more explicit. For lifecycle hooks, I think you’d need to create one of these ServerLifeCycleHandler objects:

    [https://github.com/bokeh/bokeh/blob/master/bokeh/application/handlers/server_lifecycle.py](https://github.com/bokeh/bokeh/blob/master/bokeh/application/handlers/server_lifecycle.py)

And then configure the Application with it. Certainly do-able but I have not had a chance to write up any examples for it yet (but am happy to answer any additional questions).

Same thing for themes, yes definitely can but will need to explicitly create a Theme object. Here is an example that shows how that can be done:

    [https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/bar_chart.py](https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/bar_chart.py)

Thanks,

Bryan

On Jan 11, 2017, at 3:47 PM, Luyu Wang [email protected] wrote:

Awesome!

So if embedded with Flask, can we still use server_lifecycle.py or theme.yaml to control over the Bokeh app?

On Wednesday, January 11, 2017 at 3:01:44 PM UTC-5, Bryan Van de ven wrote:
Hi,

This new example added for 0.12.4 might be of interes:

    [https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_embed.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_embed.py)

It shows how to embed a Bokeh server app in a Flask app in a single “.py” file.

Alternatively, Bokeh is extensible, you could write an custom extension to do something like what you describe:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html](http://bokeh.pydata.org/en/latest/docs/user_guide/extensions.html)

Thanks,

Bryan

On Jan 11, 2017, at 1:28 PM, Luyu Wang [email protected] wrote:

I’m implementing a data analytics app that allows users to select and upload their data files (e.g., csv or pkl) from local. It seems the current Bokeh library by itself does not support such a tool, and embedding it with Flask or Django may be the only way out. Any ideas?


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/af7035cc-3ef5-4780-a162-ec1323709b1c%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/73b2c0ae-ac74-4255-9267-9310894b0586%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/9bb67508-02e4-43f7-9efc-4b8c91234b50%40continuum.io.

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