pbugnion / ipywidgets_server

[unmaintained] Run Jupyter widgets outside of the notebook
http://ipywidgets-server.readthedocs.io/en/latest/
Other
39 stars 10 forks source link

Serve Bokeh html #11

Open DougRzz opened 6 years ago

DougRzz commented 6 years ago

Is it possible to serve an interactive Bokeh plot? I have attempted to do this by creating a html file from Bokeh and passing it to a html ipywidget but this widget will not render such a complicated html string. Do you have any ideas of how this may be done ?

pbugnion commented 6 years ago

In a notebook, you can serve a bokeh plot as part of a widget by embedding it in an output widget:

import numpy as np
from bokeh.plotting import figure, show
from bokeh.io import output_notebook

import ipywidgets as widgets

output_notebook()

x = np.random.random(size=100)
y = np.random.random(size=100)

p = figure()
p.circle(x, y)

o = widgets.Output()

with o:
    show(p)

o # display the output widget

This does not work in ipywidgets_server yet because output_notebook() seems to only work in a notebook context.

This problem will go away once we can pass custom HTML (see issue #5 ): just inject bokeh js via script tags. To make it even simpler, we could create a custom function (eg output_ipywidgets_server) that injects everything the necessary dependencies into the HTML DOM.

DougRzz commented 6 years ago

I have experimented with the output widget ..... the ipywidgets-server will only display the contents of the output widget if it contains other ipywidgets.

So I can output a Matplotlib plot if it is a Jupyter Widget. import ipympl enables the matplotlib widget.

import ipywidgets as widgets
import ipympl
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
# %matplotlib inline

out = widgets.Output()

with out:
    n = 1000
    ts = pd.Series(np.random.randn(n), index=pd.date_range('1/1/2000', periods=n))
    ts = ts.cumsum()
    ts.plot()
    plt.show()

As I understand, sometime next year, the Jupyter team intend to start work on dashboarding for Jupyterlab. Perhaps this project could be the basis for Jupyterlab dashboarding, alongside an ipywidgets GUI builder.

pbugnion commented 6 years ago

the ipywidgets-server will only display the contents of the output widget if it contains other ipywidgets.

This is not true any more (unless I'm missing something). It should have been fixed in version 0.1.2 (or thereabouts). On master, I have two examples of embedding matplotlib plots with the output widget (not using ipympl). I've also experimented with stdout and stderr, and those seem to work.

pbugnion commented 6 years ago

In fact, now that you can serve a custom static directory, you should be able to use Bokeh. I'll try and come up with a minimal working example.