Making the interact_basic produce an HTML file

I was just going through the Quickstart guide and run across one of the examples: https://github.com/bokeh/bokeh/blob/master/examples/plotting/notebook/interact_basic.ipynb

I adjusted the script so that it could work as a .py script and produce an HTML file:

from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show, output_notebook, output_file

import numpy as np
x = np.linspace(0, 2*np.pi, 2000)
y = np.sin(x)
output_file(‘Sliders.html’)
source = ColumnDataSource(data=dict(x=x, y=y))

p = figure(title=“simple line example”, plot_height=300, plot_width=600)
p.line(x, y, color="#2222aa", line_width=3, source=source, name=“foo”)
def update(f, w=1, A=1, phi=0):
if f == “sin”: func = np.sin
elif f == “cos”: func = np.cos
elif f == “tan”: func = np.tan
source.data[‘y’] = A * func(w * x + phi)
#source.push_notebook()
from IPython.html.widgets import interact
interact(update, f=[“sin”, “cos”, “tan”], w=(0,100), A=(1,10), phi=(0, 10, 0.1))
show§

``

However, this throws an error:

:0: FutureWarning: IPython widgets are experimental and may change in the future

.

Traceback (most recent call last):

File “sinusSliders.py”, line 19, in

interact(update, f=[“sin”, “cos”, “tan”], w=(0,100), A=(1,10), phi=(0, 10, 0

.1))

File "C:\Users\adi\Anaconda3\lib\site-packages\IPython\html\widgets\interactio

n.py", line 310, in interact

w = interactive(f, **kwargs)

File "C:\Users\adi\Anaconda3\lib\site-packages\IPython\html\widgets\interactio

n.py", line 184, in interactive

container = Box(_dom_classes=[‘widget-interact’])

File "C:\Users\adi\Anaconda3\lib\site-packages\IPython\html\widgets\widget_box

.py", line 40, in init

super(Box, self).init(**kwargs)

File “C:\Users\adi\Anaconda3\lib\site-packages\IPython\html\widgets\widget.py”

, line 481, in init

super(DOMWidget, self).init(*pargs, **kwargs)

File “C:\Users\adi\Anaconda3\lib\site-packages\IPython\html\widgets\widget.py”

, line 156, in init

self.open()

File “C:\Users\adi\Anaconda3\lib\site-packages\IPython\html\widgets\widget.py”

, line 174, in open

self.comm = Comm(**args)

File “C:\Users\adi\Anaconda3\lib\site-packages\IPython\kernel\comm\comm.py”, l

ine 63, in init

self.open(data)

File “C:\Users\adi\Anaconda3\lib\site-packages\IPython\kernel\comm\comm.py”, l

ine 96, in open

raise RuntimeError("Comms cannot be opened without a kernel "

RuntimeError: Comms cannot be opened without a kernel and a comm_manager attache

d to that kernel.

Is there a way to make the script produce a HTML page with sliders?

Ipython widgets require a running Ipython kernel to execute the python callbacks. There is no technical way to make then work in static rendered html. You might look into bokeh’s JS callbacks which can work in static html. (Sorry I can’t link, on my phone)

Bryan

···

On Nov 1, 2015, at 10:41, [email protected] wrote:

I was just going through the Quickstart guide and run across one of the examples: https://github.com/bokeh/bokeh/blob/master/examples/plotting/notebook/interact_basic.ipynb

I adjusted the script so that it could work as a .py script and produce an HTML file:

from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show, output_notebook, output_file

import numpy as np
x = np.linspace(0, 2*np.pi, 2000)
y = np.sin(x)
output_file(‘Sliders.html’)
source = ColumnDataSource(data=dict(x=x, y=y))

p = figure(title=“simple line example”, plot_height=300, plot_width=600)
p.line(x, y, color="#2222aa", line_width=3, source=source, name=“foo”)
def update(f, w=1, A=1, phi=0):
if f == “sin”: func = np.sin
elif f == “cos”: func = np.cos
elif f == “tan”: func = np.tan
source.data[‘y’] = A * func(w * x + phi)
#source.push_notebook()
from IPython.html.widgets import interact
interact(update, f=[“sin”, “cos”, “tan”], w=(0,100), A=(1,10), phi=(0, 10, 0.1))
show§

``

However, this throws an error:

:0: FutureWarning: IPython widgets are experimental and may change in the future

.

Traceback (most recent call last):

File “sinusSliders.py”, line 19, in

interact(update, f=[“sin”, “cos”, “tan”], w=(0,100), A=(1,10), phi=(0, 10, 0

.1))

File "C:\Users\adi\Anaconda3\lib\site-packages\IPython\html\widgets\interactio

n.py", line 310, in interact

w = interactive(f, **kwargs)

File "C:\Users\adi\Anaconda3\lib\site-packages\IPython\html\widgets\interactio

n.py", line 184, in interactive

container = Box(_dom_classes=[‘widget-interact’])

File "C:\Users\adi\Anaconda3\lib\site-packages\IPython\html\widgets\widget_box

.py", line 40, in init

super(Box, self).init(**kwargs)

File “C:\Users\adi\Anaconda3\lib\site-packages\IPython\html\widgets\widget.py”

, line 481, in init

super(DOMWidget, self).init(*pargs, **kwargs)

File “C:\Users\adi\Anaconda3\lib\site-packages\IPython\html\widgets\widget.py”

, line 156, in init

self.open()

File “C:\Users\adi\Anaconda3\lib\site-packages\IPython\html\widgets\widget.py”

, line 174, in open

self.comm = Comm(**args)

File “C:\Users\adi\Anaconda3\lib\site-packages\IPython\kernel\comm\comm.py”, l

ine 63, in init

self.open(data)

File “C:\Users\adi\Anaconda3\lib\site-packages\IPython\kernel\comm\comm.py”, l

ine 96, in open

raise RuntimeError("Comms cannot be opened without a kernel "

RuntimeError: Comms cannot be opened without a kernel and a comm_manager attache

d to that kernel.

Is there a way to make the script produce a HTML page with sliders?

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/4d0827d9-e089-48ef-a0f6-918b769b2468%40continuum.io.

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