Skip to content

Instantly share code, notes, and snippets.

@marckassay
Created December 17, 2020 17:04
Show Gist options
  • Save marckassay/70284c49345ec54cdb2aac8f1db88a90 to your computer and use it in GitHub Desktop.
Save marckassay/70284c49345ec54cdb2aac8f1db88a90 to your computer and use it in GitHub Desktop.
pyviz/pyviz Gitter example of potential issue.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import holoviews as hv\n",
"import panel as pn\n",
"import param\n",
"from holoviews import opts\n",
"from bokeh.sampledata.iris import flowers\n",
"from holoviews.operation import gridmatrix\n",
"from holoviews.streams import Selection1D, Stream\n",
"\n",
"hv.extension('bokeh')\n",
"\n",
"print('holoviews: ', hv.__version__)\n",
"print('panel: ', pn.__version__)\n",
"print('param: ', param.__version__)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"iris_ds = hv.Dataset(flowers, kdims=['sepal_length','sepal_width','petal_length','petal_width'])\n",
"iris_ds.dframe().head(3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"grid = gridmatrix(iris_ds, diagonal_type=hv.Distribution, chart_type=hv.Points).opts(\n",
" opts.GridMatrix(shared_datasource=True, merge_tools=True),\n",
" opts.Points(tools=['hover', 'box_select', 'lasso_select', 'tap'], active_tools=['box_select'],\n",
" shared_datasource=True),\n",
" opts.Distribution(shared_datasource=False, shared_axes=False))\n",
"\n",
"table = hv.Table(iris_ds, kdims=['sepal_length','sepal_width','petal_length','petal_width']).opts(\n",
" selectable=True, toolbar=None, shared_datasource=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"select_table = Stream.define('Selected', selected=[])()\n",
"table_selected = Selection1D(source=table)\n",
"\n",
"@param.depends(index=table_selected.param.index)\n",
"def reactive_grid(index):\n",
" if len(index) != 0: \n",
" return grid.apply.opts(selected=index)\n",
" else:\n",
" return grid\n",
" \n",
"@param.depends(selected=select_table.param.selected)\n",
"def reactive_table(selected):\n",
" table_selected.update(index=selected)\n",
" return table.apply.opts(selected=selected)\n",
"\n",
"pn.Column(reactive_grid, reactive_table)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:notebook] *",
"language": "python",
"name": "conda-env-notebook-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment