Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed Holomap and tabs misbehaves when saved as html file #1083

Closed
Jacob-Barhak opened this issue Feb 8, 2020 · 4 comments · Fixed by #1543
Closed

Embed Holomap and tabs misbehaves when saved as html file #1083

Jacob-Barhak opened this issue Feb 8, 2020 · 4 comments · Fixed by #1543
Milestone

Comments

@Jacob-Barhak
Copy link
Contributor

The following code attempts to create a history plot with a year slider that shows animation for multiple categories.

If the plot is created outside a notebook , the first tab freezes and does not change when the year slider is dragged. The second tab works fine. This bug happens in both python 2 and 3, yet the script is reported to work well within Jupyter notebook.

The bug shows in:
python 2.7.16
panel 0.8
holoviews 1.12.7
bokeh 1.4.0

Here is code to reproduce the defective html file

import holoviews as hv
import panel as pn
import bokeh
from bokeh.resources import INLINE
import sys

hv.extension('bokeh')
pn.extension(safe_embed=True) 

print ("Python version is: %s"%sys.version)
for library in [hv,pn,bokeh]:
    print ("%s version %s"% ( library.__name__, library.__version__))

horizontal_limits = (2010,2035)
text_offset_x = 0
text_offset_y = 20

def save_file(file_name, plot_object, tabs_values, title):
    if tabs_values == None:            
        save_object = pn.pane.HoloViews(plot_object)
    else:   
        TabList =  list(zip(tabs_values,plot_object))
        save_object = pn.layout.Tabs(*TabList)
    save_object.save(file_name, resources=INLINE, title = title, embed=True)

data = {}

data['Year'] =                [2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, ]
data['Cohorts'] =             [  22,   34,   40,   47,   47,   91,   91,  123,  123, ]
data['Validations'] =         [ 150,  157,  190,  224,  224,  367,  367,  471,  471, ]

innovations =  {}
innovations[2012] = 'The Reference Model created'
innovations[2013] = 'MIST, HPC, Cloud Computing'
innovations[2014] = 'Evolutionary Computation\nfor Population Generation'
innovations[2015] = 'Object Oriented\n Population Generation'
innovations[2016] = 'Assumption Engine\n Cooperative Ensemble Model'
innovations[2017] = 'ClinicalTrials.Gov Interface'
innovations[2018] = 'Knowledge Gap\nInteractive Visualization'
innovations[2019] = 'Improved Interactive Visualization'
innovations[2020] = 'Include Human Interpretation'

all_dims = data.keys()

vertical_dims = list(set(all_dims) - set(['Year']))
print (vertical_dims)

plot_dicts = [{} for vertical_dim in vertical_dims]
for (year_index,year) in enumerate(data['Year']):
    up_to_year_data = dict( [ (Key, Value[:year_index+1])  for (Key,Value)  in data.items()])
    for (vertical_enum,vertical_dim) in enumerate(vertical_dims):    
        max_y = max(data[vertical_dim])
        point_figure = hv.Points(up_to_year_data, kdims=['Year',vertical_dim])
        spike_figure = hv.Spikes(up_to_year_data, kdims=['Year'], vdims=[vertical_dim])
        text_figure_x = year+text_offset_x
        text_figure_y = min(up_to_year_data[vertical_dim][year_index]+text_offset_y, max_y)
        text_figure = hv.Text(text_figure_x, text_figure_y, innovations[year], halign = 'left').redim(x='Year',y=vertical_dim)
        point_figure_improved = (point_figure).opts (xlim = horizontal_limits, ylim = (0, max_y*2), toolbar=None, default_tools=[], width=500, height=500)
        text_figure_improved = (text_figure).opts (xlim = horizontal_limits, ylim = (0, max_y*2), toolbar=None, default_tools=[], width=500, height=500)
        spike_figure_improved = (spike_figure).opts (xlim = horizontal_limits, ylim = (0, max_y*2), toolbar=None, default_tools=[], width=500, height=500)
        merged_figure = point_figure_improved*spike_figure_improved*text_figure_improved
        save_file(vertical_dim+str(year), merged_figure, None, True)
        plot_dicts[vertical_enum][year] = merged_figure

tab_plots = []
for (vertical_enum,vertical_dim) in enumerate(vertical_dims):    
    tab_plots.append( hv.HoloMap(plot_dicts[vertical_enum], kdims='Year').collate().opts( toolbar=None, shared_axes=False) )

save_file('TheReferenceModelHistory', tab_plots, vertical_dims, 'The Reference Model History')

Here is the bug illustrated:
In the plot below, the slider shows 2016, yet the 2012 image is shown - the 2016 image is generated properly - the script saves all images, yet for some reason the HoloMap is not functional.

image

The HoloMap works nicely in the scond Tab that responds to sliding the slider properly - see below:
image

@philippjfr
Copy link
Member

Thanks for the issue, this is a duplicate of #1083 so I'll close.

@Jacob-Barhak
Copy link
Contributor Author

Sorry Philipp,

If you are closing it because #1083 is a duplicate of itself #1083, then please reopen. I assume you mean a duplicate of another issue.
If you fixed it in version 0.10.0, then I will gladly test it again.

Hopefully it is really fixed.

      Jacob

@philippjfr
Copy link
Member

Yes sorry, it's a duplicate of #806.

@Jacob-Barhak
Copy link
Contributor Author

Thanks Philipp,

Yes this is now working with Python 3.7. I just tested it with the development version.

It opens some possible new visualization options for the future.

Many thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants