7
votes

I'm trying to create an environment in which I develop Python code with PyCharm while at the same time creating interactive charts using holoviews and bokeh.

I followed steps in Holoview Introduction and it works in Jupyter notebook - the charts are nicely interactive indeed. However, when I run the same code in PyCharm's Python Console, no charts or browser shows up.

In contrast, when I directly call bokeh's methods, as in this example, a browser launches and I can manipulate the charts interactively. I would like to achieve this using holoviews (+bokeh).

Many thanks for your help in advance.

My libraries:

  • Python 3.4.5
  • holoviews 1.8.1
  • bokeh 0.12.6
  • param 1.5.1
  • ipython 6.1.0
  • jupyter 1.0.0
  • pandas 0.20.3
  • numpy 1.13.1
  • scipy 0.19.1
2

2 Answers

6
votes

The only thing you need to add to your code is show(hv.render(your_holoviews_plot)), like this:

import holoviews as hv
hv.extension('bokeh')
from bokeh.plotting import show

show(hv.render(your_holoviews_plot))

When you run your script in PyCharm (or any other IDE), this will open your plot in the browser.

It sets bokeh as renderer and uses bokeh.plotting.show() to open the plot in the browser.
So no need to go to the commandline etc.

Full working example code:

# import libraries
import numpy as np
import pandas as pd
import hvplot.pandas
import holoviews as hv

# setting bokeh as backend
hv.extension('bokeh')

# going to use show() to open plot in browser
from bokeh.plotting import show

# create some sample data
data = np.random.normal(size=[50, 2])
df = pd.DataFrame(
    data=data,
    columns=['col1', 'col2'],
)

# using hvplot here to create a holoviews plot
# could have also just used holoviews itself
plot = df.hvplot(kind='scatter', x='col1', y='col2')

# use show() from bokeh
show(hv.render(plot))
5
votes

The solution is in: http://holoviews.org/user_guide/Deploying_Bokeh_Apps.html

you need these lines of code:

import holoviews.plotting.bokeh
....
layout=#whathever holoview you want to plot
...
doc = hv.renderer('bokeh').server_doc(layout)

And then go to your command prompt, cd to the right directory and run: bokeh serve --show myscript.py