holoviz / hvplot

A high-level plotting API for pandas, dask, xarray, and networkx built on HoloViews
https://hvplot.holoviz.org
BSD 3-Clause "New" or "Revised" License
1.07k stars 104 forks source link

Groupby toggle in Bar-Chart does work in Jupyter-Lab but not in .html #506

Open mc51 opened 4 years ago

mc51 commented 4 years ago

Here's my conda environment. I'm on Windows 10. Using Firefox 79.0 and Chrome 84.0.4147.135.

Description of expected behavior and the observed behavior

Using the following code, I'd expect the same behavior in both cases. However, while the first plot works flawlessly in Jupyterlab and the browser, the second plot does work in Jupyterlab but not in the browser.

Complete, minimal, self-contained example code that reproduces the issue

import numpy as np
import pandas as pd
import hvplot.pandas

df = pd.DataFrame({"value": [1, 2, 3, 5, 4, 3], "group": [1, 1, 1, 2, 2, 2] })

# This works in Jupyterlab + Browser
df.hvplot.bar(by="group").groupby("group").opts(width=400)

# This works in Jupyterlab, but the toggle doesn't work in the browser
df.hvplot.bar(groupby="group").opts(width=400)

There is no error output in the dev console.

Here what happens in the browser: 2020-09-02_bokeh_groupby_toggle_bug

mc51 commented 4 years ago

I've played around some more. This example straight from the user guide does not work as well. I guess it's the same issue:

import panel as pn
import hvplot.pandas  # noqa
from bokeh.sampledata.iris import flowers
flowers.hvplot.bivariate(x='sepal_width', y='sepal_length', width=600, 
                         groupby='species')

I've tried with the latest versions of hvplot, bokeh and panel. (this is on a different [Linux] machine as before, just to make sure it was not device specific)

I've also tried older versions up to hvplot 0.5.2 and bokeh 2.0.2. Same outcome.

philippjfr commented 4 years ago

hvPlot does not embed all the data in the notebook and therefore an exported HTML on purpose as you would quickly reach huge file sizes. So by default the output requires a live Python kernel attached. If you do want to embed the output you can set dynamic=False in the hvplot call. I'd happily accept some documentation about this in the https://hvplot.holoviz.org/user_guide/Viewing.html guide.

mc51 commented 4 years ago

Interesting enough, with the above mentioned setup (latest current versions), I started to get this error message:

Traceback (most recent call last):
  File "C:\Users\MyUser\Software\Anaconda3\lib\site-packages\pyviz_comms\__init__.py", line 316, in _handle_msg
    self._on_msg(msg)
  File "C:\Users\MyUser\Software\Anaconda3\lib\site-packages\panel\viewable.py", line 242, in _on_msg
    patch.apply_to_document(doc, comm.id)
  File "C:\Users\MyUser\Software\Anaconda3\lib\site-packages\bokeh\protocol\messages\patch_doc.py", line 100, in apply_to_document
    doc._with_self_as_curdoc(lambda: doc.apply_json_patch(self.content, setter))
  File "C:\Users\MyUser\Software\Anaconda3\lib\site-packages\bokeh\document\document.py", line 1150, in _with_self_as_curdoc
    return f()
  File "C:\Users\MyUser\Software\Anaconda3\lib\site-packages\bokeh\protocol\messages\patch_doc.py", line 100, in <lambda>
    doc._with_self_as_curdoc(lambda: doc.apply_json_patch(self.content, setter))
  File "C:\Users\MyUser\Software\Anaconda3\lib\site-packages\bokeh\document\document.py", line 398, in apply_json_patch
    self._trigger_on_message(event_json["msg_type"], event_json["msg_data"])
  File "C:\Users\MyUser\Software\Anaconda3\lib\site-packages\bokeh\document\document.py", line 687, in _trigger_on_message
    cb(msg_data)
  File "C:\Users\MyUser\Software\Anaconda3\lib\site-packages\bokeh\document\document.py", line 348, in apply_json_event
    event = Event.decode_json(json)
  File "C:\Users\MyUser\Software\Anaconda3\lib\site-packages\bokeh\events.py", line 167, in decode_json
    raise ValueError("Could not find appropriate Event class for event_name: %r" % event_name)
ValueError: Could not find appropriate Event class for event_name: 'document_ready'

Setting dynamic=False, the error disappears and the .html output is as expected. Issue solved! Thanks a lot, you really saved me after quite a few hours of despair.

I'll be happy to contribute to the docs. Unfortunately, it will take a while until I'll find the time for that.

maximlt commented 1 year ago

The task is to document dynamic=False in the context of exporting a plot to HTML.