holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.7k stars 403 forks source link

Hook to hv.Table do not work with hv.DynamicMap #4343

Open PeterFogh opened 4 years ago

PeterFogh commented 4 years ago

ALL software version info

Unix - "Ubuntu 18.04.4 LTS (Bionic Beaver)" Python Libraries: holoviews 1.12.7, pandas 1.0.1 Browser: Google Chrome

Description of expected behavior and the observed behavior

I present here a simplified example of my original plot to present the specific problem. I have a hv.Table which updates using a hv.DynamicMap (a value selector). My table has some columns which contain long strings, thus I want to customize the width of some of the columns. This is possible using holoviews hooks, as seen in the example below. However, when the hv.DynamicMap updates the table, the column width customization does not take effect, as shown in the screenshots below.

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

%load_ext watermark
import holoviews as hv
import pandas as pd
hv.extension('bokeh')
print('Watermark of notebook execution:')
%watermark -iv

def table(data_id):
    def column_width(plot, element):
        plot.handles['table'].columns[0].width = 1400
        plot.handles['table'].columns[2].width = 1400

    df = pd.DataFrame({
        'x': [data_id*10**12]*4,
        'y': [1, 2, 3, 4],
        'z': [data_id*10**12]*4})

    hv_table = hv.Table(df).opts(
        width=400, height=200, hooks=[column_width])
    return hv_table

dmap_table = hv.DynamicMap(table, kdims=['data_id']).redim.values(
    data_id=[0, 1])
dmap_table

Screenshots or screencasts of the bug in action

The initial plot: Screenshot from 2020-03-31 10-20-14

The plot after selecting another kdims value. Screenshot from 2020-03-31 10-20-40

PeterFogh commented 4 years ago

See also discussion at https://discourse.holoviz.org/t/hook-to-hv-table-do-not-work-with-hv-dynamicmap/443.

suiluj commented 3 years ago

I noticed that column width resizing did not work until i changed the default autosize_mode

Disclaimer: I do not use DynamicMap but hvplot but this hook works for me:

def hide_index(plot, element):
    plot.handles['table'].autosize_mode = "none" # column resizing does not work without this line
    plot.handles['table'].columns[2].width = 60

More details here: autosize_mode doc