0

Note: for anyone are experiencing the same issue, a temporary work around I am using is found here Bokeh, how to change column used for glyph colors with CustomJS callbacks? although this is not sufficient as the interact feature is needed

Any help and suggestions are appreciated! :) However, do keep in mind I may be restricted due to the setup of our systems. I have provided as extensive help information as I could, do let me know if any other information will help.

I am creating a template for my company with Jupyter notebook and Bokeh. I have been successful so far until this particular issue. The 'interact' method which would allow for a user to change e.g. the colour of the datapoints via a dropdown menu does not load. I have tried many solutions, most of which are consistent with the following:

jupyter nbextension enable --py widgetsnbextension
jupyter nbextension enable --py --sys-prefix widgetsnbextension

Furthermore, I have also tried solutions requested on the following url all the way through but had no luck: https://github.com/jupyter-widgets/ipywidgets/issues/1745

Code that errors:

import pandas as pd
import numpy as np
#import exmaple dataset
from sklearn import datasets
#import clustering methods
from sklearn.cluster import KMeans
from sklearn.cluster import SpectralClustering

#import Bokeh
import bokeh
from bokeh.plotting import figure 
from bokeh.io import output_notebook, show
from bokeh.layouts import widgetbox, gridplot
from bokeh.models import Select, CustomJS, ColumnDataSource
from bokeh.models.widgets import Dropdown
from ipywidgets import interact
from bokeh.io import push_notebook
#Initialise Bokeh into the notebook to display graphs with interactive toolbar
output_notebook()
p3 = figure(title="test", plot_height=300, plot_width=600)
colors = [colormap[x] for x in y]
p3.circle(f1, f2, size=10, color=colors)

h = show(p3, notebook_handle=True)

def update(f):#f=["Actual", "Kmeans", "Spectral"]
    colormap = {1: 'red', 2: 'green', 0: 'blue'}
    if f == "Actual":
        the_x = np.array(list(zip(f1, f2)))
        the_y = y
        colors = [colormap[x] for x in the_y]
    elif f == "Kmeans":
        the_x = np.array(list(zip(f1, f2)))
        kmeans = KMeans(n_clusters=3)
        # Fitting the input data
        kmeans = kmeans.fit(the_x)
        # Getting the cluster labels
        the_y = kmeans.predict(the_x)
        colors = [colormap[x] for x in the_y]
    elif f == "Spectral":
        the_x = np.array(list(zip(f1, f2)))
        clustering = SpectralClustering(n_clusters=3, assign_labels="discretize", random_state=0).fit(the_x)
        the_y = clustering.labels_
        colors = [colormap[x] for x in the_y]
    #p3.circle(f1, f2, size=10, color=colors)
    push_notebook(handle=h)

interact(update, f=["Actual", "Kmeans", "Spectral"])#this line here

Error displayed:

<function __main__.update(f)>

Versions Information

conda --version
conda 4.5.4

conda info
     active environment : bokeh_test_2_1
    active env location : /home/xxxxxxx/.conda/envs/bokeh_test_2_1
            shell level : 1
       user config file : /home/xxxxxxx/.condarc
 populated config files : /home/xxxxxxx/.condarc
          conda version : 4.5.4
    conda-build version : 3.0.27
         python version : 2.7.14.final.0
       base environment : /opt/cloudera/parcels/Anaconda  (read only)
           channel URLs : xxxxxxx/current/anaconda-suite/pkgs/linux-64
                          xxxxxxx/current/anaconda-suite/pkgs/noarch
          package cache : /opt/cloudera/parcels/Anaconda/pkgs
                          /home/xxxxxxx/.conda/pkgs
       envs directories : /home/xxxxxxx/.conda/envs
                          /opt/cloudera/parcels/Anaconda/envs
               platform : linux-64
             user-agent : conda/4.5.4 requests/2.18.4 CPython/2.7.14 Linux/3.10.0-862.11.6.el7.x86_64 rhel/7.5 glibc/2.17
                UID:GID : xxxxxxx
             netrc file : None
           offline mode : False

jupyter nbextension list
Known nbextensions:
  config dir: /home/xxxxxxxx/.conda/envs/bokeh_test_2_1/etc/jupyter/nbconfig
    notebook section
      jupyter-js-widgets/extension  enabled 
      - Validating: OK

jupyter --paths
config:
    /home/xxxxxxxx/.jupyter
    /home/xxxxxxxx/.conda/envs/bokeh_test_2_1/etc/jupyter
    /usr/local/etc/jupyter
    /etc/jupyter
data:
    /home/xxxxxxxx/.local/share/jupyter
    /home/xxxxxxxx/.conda/envs/bokeh_test_2_1/share/jupyter
    /usr/local/share/jupyter
    /usr/share/jupyter
runtime:
    /home/xxxxxxxx/.local/share/jupyter/runtime

(bokeh_test_2_1) xxxx@xxxx-xxxxxxxxx $ conda list
# packages in environment at /home/xxxxxxxx/.conda/envs/bokeh_test_2_1:
#
# Name                    Version   
_tflow_180_select         3.0
absl-py                   0.2.2    
astor                     0.6.2                          
backcall                  0.1.0                          
blas                      1.0       
bleach                    1.5.0                          
bokeh                     0.12.16                        
ca-certificates           2018.03.07        
certifi                   2018.4.16                      
dbus                      1.13.2                     
decorator                 4.3.0                          
entrypoints               0.2.3                  
expat                     2.2.5                     
fontconfig                2.12.6                    
freetype                  2.8                        
gast                      0.2.0                          
glib                      2.56.1                     
gmp                       6.1.2                      
grpcio                    1.11.0                 
gst-plugins-base          1.14.0                     
gstreamer                 1.14.0                     
h5py                      2.8.0                  
hdf5                      1.10.2                     
html5lib                  0.9999999                      
icu                       58.2                       
intel-openmp              2018.0.0     
ipykernel                 4.8.2                          
ipython                   6.4.0                          
ipython_genutils          0.2.0                  
ipywidgets                7.2.1                          
jedi                      0.12.0                         
jinja2                    2.10                   
jpeg                      9b                    
jsonschema                2.6.0                  
jupyter                   1.0.0                     
jupyter_client            5.2.3                          
jupyter_console           5.2.0             
jupyter_core              4.4.0             
keras                     2.1.6                          
libedit                   3.1.20170329          
libffi                    3.2.1                 
libgcc-ng                 7.2.0                 
libgfortran-ng            7.2.0                 
libpng                    1.6.34                
libprotobuf               3.5.2                 
libsodium                 1.0.16                
libstdcxx-ng              7.2.0                 
libxcb                    1.13                  
libxml2                   2.9.8                 
markdown                  2.6.11                         
markupsafe                1.0               
mistune                   0.8.3             
mkl                       2018.0.2        
mkl_fft                   1.0.1             
mkl_random                1.0.1                  
nbconvert                 5.3.1             
nbformat                  4.4.0             
ncurses                   6.1                   
notebook                  5.5.0                          
numpy                     1.14.3            
numpy-base                1.14.3            
openssl                   1.0.2o                
packaging                 17.1                           
pandas                    0.23.0            
pandoc                    1.19.2.1              
pandocfilters             1.4.2             
parso                     0.2.0                          
pcre                      8.42                  
pexpect                   4.5.0                          
pickleshare               0.7.4             
pip                       10.0.1                         
prompt_toolkit            1.0.15            
protobuf                  3.5.2                  
ptyprocess                0.5.2             
py4j                      0.10.6            
pygments                  2.2.0             
pyparsing                 2.2.0             
pyqt                      5.9.2             
pyspark                   2.3.0                          
python                    3.6.5                 
python-dateutil           2.7.3                          
pytz                      2018.4                         
pyyaml                    3.12              
pyzmq                     17.0.0            
qt                        5.9.5                 
qtconsole                 4.3.1             
readline                  7.0                   
scikit-learn              0.19.1            
scipy                     1.1.0             
send2trash                1.5.0                          
setuptools                39.2.0                         
simplegeneric             0.8.1                     
sip                       4.19.8                 
six                       1.11.0            
sqlite                    3.23.1                
tensorboard               1.8.0                  
tensorflow                1.8.0                 
tensorflow-base           1.8.0             
termcolor                 1.1.0                          
terminado                 0.8.1                          
testpath                  0.3.1             
tk                        8.6.7                 
tornado                   5.0.2                          
traitlets                 4.3.2             
wcwidth                   0.1.7             
werkzeug                  0.14.1                         
wheel                     0.31.1                         
widgetsnbextension        3.2.1                          
xz                        5.2.4                 
yaml                      0.1.7                 
zeromq                    4.2.5                 
zlib                      1.2.11
bigreddot
  • 33,642
  • 5
  • 69
  • 122
HamishLacmane
  • 88
  • 1
  • 11
  • That 's not an error, per se, that's the default `repr` for interact objects if the `ipywidgets` extension is not installed/enabled properly. I don't have any suggestions for why that might be. I have removed the `bokeh` tag, since this is not a question about Bokeh. As an aside, you might consider a Bokeh app embedded in the notebook as an alternative to `ipywidgets`: https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/notebook_embed.ipynb – bigreddot Oct 16 '18 at 15:47
  • @bigreddot I tried running the notebook you have linked, and it does not output anything. :/ – HamishLacmane Oct 17 '18 at 08:09
  • Did you actually run it on a local notebook server? A static render won't function. If the notebook url is not the default notebook url, you will need to pass `notebook_url` as an argument to `show` – bigreddot Oct 17 '18 at 14:09
  • First of all, the message you are seeing is not an error. It is the string representation of the return value of the call to interact. This is shown whether your matplotlib backend is enabled or not. You can suppress this by adding a semicolon at the end of the line in which you call interact. – rje Oct 17 '18 at 16:38
  • Furthermore, your code is incomplete so I cannot run it to see what goes wrong. If you create a simpler example, let's say without bokeh but with `%matplotlib inline` and a very simple interactive function, does this still occur? Please show minimal code that still gives this problem. – rje Oct 17 '18 at 16:40
  • Just another thought: is there any chance that you might be running jupyter lab instead of jupyter notebook? In that case your question might be solved by running `jupyter labextension install @jupyter-widgets/jupyterlab-manager` – rje Oct 17 '18 at 16:51

0 Answers0