nteract / hydrogen

:atom: Run code interactively, inspect data, and plot. All the power of Jupyter kernels, inside your favorite text editor.
https://nteract.gitbooks.io/hydrogen/
MIT License
3.92k stars 334 forks source link

Holoviews with Bokeh backend does not work in Hydrogen #1976

Open bu2 opened 4 years ago

bu2 commented 4 years ago

Prerequisites

Description

I try to use Holoviews with Bokeh backend in Hydrogen and I do not get any output plot. When I switch to Matplotlib backend for Holoviews it seems to work.

Steps to Reproduce

  1. Sample Python code to reproduce the problem:
# %%

import sys
import holoviews
import holoviews.operation.datashader as hd

print('Python version: ' + sys.version)
print('Holoviews version: ' + holoviews.__version__)

# %%

holoviews.extension('bokeh')
holoviews.output(backend='bokeh')

# %%

import pandas as pd
import numpy as np
import datashader as ds
import datashader.transfer_functions as tf
from collections import OrderedDict as odict

num = 100000
np.random.seed(1)

dists = {cat: pd.DataFrame(odict([('x', np.random.normal(x, s, num)),
                                  ('y', np.random.normal(y, s, num)),
                                  ('val', val),
                                  ('cat', cat)]))
         for x,  y,  s,  val, cat in
         [(2, -2, 0.10, 20, "d2"),
          (-2, -2, 0.50, 30, "d3"),
          (-2, 2, 1.00, 40, "d4"),
          (0, 0, 3.00, 50, "d5")]}

df = pd.concat(dists, ignore_index=True)
df["cat"] = df["cat"].astype("category")

# %%

points = holoviews.Points(df.sample(10000))
points

# %%

agg = ds.Canvas().points(df, 'x', 'y')
hd.datashade(points) + hd.shade(holoviews.Image(agg)) + holoviews.RGB(np.array(tf.shade(agg).to_pil()))
  1. If you replace bokeh backend by matplotlib (at top of file), it should work:
holoviews.extension('matplotlib')

holoviews.output(backend='matplotlib')

Versions

OS version: I run Atom on macOS 10.15. My Jupyter kernel run from a docker container based on this image: rapidsai/rapidsai-dev-nightly:0.15-cuda10.1-devel-ubuntu18.04-py3.7

atom --version

Atom    : 1.48.0
Electron: 5.0.13
Chrome  : 73.0.3683.121
Node    : 12.0.0

apm --version

apm  2.5.0
npm  6.14.5
node 10.20.1 x64
atom 1.48.0
python 3.7.6
git 2.24.3

Hydrogen version: Hydrogen 2.14.3

Plugins

Have you installed and activated any of the Hydrogen plugins below ?

Logs

I got this Javascript related error in the output of the following python instruction:

holoviews.extension('bokeh')

SyntaxError: Unexpected token ? at runCodeHere (/Users/bu2/.atom/packages/Hydrogen/node_modules/@nteract/outputs/lib/components/media/javascript.js:16:21) at JavaScript.componentDidMount (/Users/bu2/.atom/packages/Hydrogen/node_modules/@nteract/outputs/lib/components/media/javascript.js:34:9) at Ji (/Users/bu2/.atom/packages/Hydrogen/node_modules/react-dom/cjs/react-dom.production.min.js:212:132) at Sj (/Users/bu2/.atom/packages/Hydrogen/node_modules/react-dom/cjs/react-dom.production.min.js:255:229) at exports.unstable_runWithPriority (/Users/bu2/.atom/packages/Hydrogen/node_modules/scheduler/cjs/scheduler.production.min.js:19:467) at cg (/Users/bu2/.atom/packages/Hydrogen/node_modules/react-dom/cjs/react-dom.production.min.js:122:325) at Jj (/Users/bu2/.atom/packages/Hydrogen/node_modules/react-dom/cjs/react-dom.production.min.js:248:370) at yj (/Users/bu2/.atom/packages/Hydrogen/node_modules/react-dom/cjs/react-dom.production.min.js:239:376) at /Users/bu2/.atom/packages/Hydrogen/node_modules/react-dom/cjs/react-dom.production.min.js:123:115 at exports.unstable_runWithPriority (/Users/bu2/.atom/packages/Hydrogen/node_modules/scheduler/cjs/scheduler.production.min.js:19:467) at cg (/Users/bu2/.atom/packages/Hydrogen/node_modules/react-dom/cjs/react-dom.production.min.js:122:325) at fg (/Users/bu2/.atom/packages/Hydrogen/node_modules/react-dom/cjs/react-dom.production.min.js:123:61) at gg (/Users/bu2/.atom/packages/Hydrogen/node_modules/react-dom/cjs/react-dom.production.min.js:122:496) at Ig (/Users/bu2/.atom/packages/Hydrogen/node_modules/react-dom/cjs/react-dom.production.min.js:230:156) at Object.enqueueForceUpdate (/Users/bu2/.atom/packages/Hydrogen/node_modules/react-dom/cjs/react-dom.production.min.js:133:76) at ResultViewComponent.F.forceUpdate (/Users/bu2/.atom/packages/Hydrogen/node_modules/react/cjs/react.production.min.js:12:456) at e.onInvalidate (/Users/bu2/.atom/packages/Hydrogen/node_modules/mobx-react/dist/mobxreact.cjs.production.min.js:1:3180) at e.runReaction (/Users/bu2/.atom/packages/Hydrogen/node_modules/mobx/lib/mobx.min.js:1:26685) at runReactionsHelper (/Users/bu2/.atom/packages/Hydrogen/node_modules/mobx/lib/mobx.min.js:1:28732) at reactionScheduler (/Users/bu2/.atom/packages/Hydrogen/node_modules/mobx/lib/mobx.min.js:1:28230) at runReactions (/Users/bu2/.atom/packages/Hydrogen/node_modules/mobx/lib/mobx.min.js:1:28314) at endBatch (/Users/bu2/.atom/packages/Hydrogen/node_modules/mobx/lib/mobx.min.js:1:23125) at _endAction (/Users/bu2/.atom/packages/Hydrogen/node_modules/mobx/lib/mobx.min.js:1:14750) at executeAction (/Users/bu2/.atom/packages/Hydrogen/node_modules/mobx/lib/mobx.min.js:1:14121) at OutputStore.n (/Users/bu2/.atom/packages/Hydrogen/node_modules/mobx/lib/mobx.min.js:1:13939) at /Users/bu2/.atom/packages/Hydrogen/lib/result.js:66:23 at /Users/bu2/.atom/packages/Hydrogen/lib/kernel.js:379:9 at /Users/bu2/.atom/packages/Hydrogen/lib/kernel.js:312:9 at wrappedOnResults (/Users/bu2/.atom/packages/Hydrogen/lib/kernel.js:78:5) at future.onIOPub (/Users/bu2/.atom/packages/Hydrogen/lib/ws-kernel.js:49:7)

Expected behavior

I want to plot in Hydrogen with Holoviews (so then I can use interactive Datashader)

Thanks for your help.

pedrolagomarsino commented 2 years ago

Is there any updates on this? bokeh and interactive plots have never work on Hydrogen for me, but It would be fantastic if they would.