Skip to content

Commit

Permalink
Updated Dashboard_Demo notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Dec 19, 2017
1 parent c1b0e7d commit 056a908
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions notebooks/Dashboard_Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"urth": {
"dashboard": {
"hidden": true
Expand All @@ -20,7 +19,7 @@
"import geoviews as gv\n",
"\n",
"from cartopy import feature as cf\n",
"from paramnb import NbParams, FileSelector\n",
"from paramnb import Widgets\n",
"\n",
"hv.notebook_extension(width=90)\n",
"%output widgets='live' size=400\n",
Expand All @@ -37,14 +36,13 @@
}
},
"source": [
"Declaring a set of widgets using paramNB is as simply as declaring a Parameterized class. Here we declare a ``CubeLoader`` class with a ``FileSelector`` parameter, a cache and a load method, which will load cubes from a file on disk. The ``NbParams`` function accepts the ``CubeLoader`` instance and generates a dropdown widget for the ``cube_path`` from it. By declaring a callback we can tell it to load the file from disk (or the cache) whenever the user executes the widget. Finally we can declare the ``execute`` mode, which allows declaring no execution with ``execute=None`` or adds a button to execute the 'next' cell or all cells 'below'."
"Declaring a set of widgets using paramNB is as simply as declaring a Parameterized class. Here we declare a ``CubeLoader`` class with a ``FileSelector`` parameter, a cache and a load method, which will load cubes from a file on disk. The ``Widgets`` function accepts the ``CubeLoader`` instance and generates a dropdown widget for the ``cube_path`` from it. By declaring a callback we can tell it to load the file from disk (or the cache) whenever the user executes the widget and ``next_n=1`` will ensure the next cell is run whenever the value changes:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"urth": {
"dashboard": {
"layout": {
Expand All @@ -60,13 +58,13 @@
"source": [
"class CubeLoader(param.Parameterized):\n",
" \n",
" cube_path = FileSelector(default='files/*.pp')\n",
" cube_path = param.FileSelector(path='./files/*')\n",
"\n",
" cache = {}\n",
" cubes = None\n",
" \n",
" @classmethod\n",
" def load(cls, cube_loader):\n",
" def load(cls, cube_path):\n",
" if cls.cube_path not in cls.cache:\n",
" cubelist = iris.load(cls.cube_path)\n",
" for c in cubelist:\n",
Expand All @@ -78,14 +76,13 @@
" cubes = {cb.vdims[0].name:cb for cb in [hv.Dataset(c) for c in cubelist]} # Load cubes into dictionary\n",
" cls.cubes = {k:v for k,v in cubes.items() if k!='unknown'} # Filter as desired\n",
"\n",
"NbParams(CubeLoader, execute='next', callback=CubeLoader.load)"
"Widgets(CubeLoader, next_n=1, callback=CubeLoader.load)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"urth": {
"dashboard": {
"layout": {
Expand Down Expand Up @@ -117,7 +114,7 @@
" cmap = param.ObjectSelector(default='viridis',\n",
" objects=list(cmap_d.keys()))\n",
"\n",
" quantity = param.ObjectSelector(default=CubeLoader.cubes.keys()[0],\n",
" quantity = param.ObjectSelector(default=list(CubeLoader.cubes.keys())[0],\n",
" objects=list(CubeLoader.cubes.keys()))\n",
"\n",
" element = param.ObjectSelector(default=gv.Image,\n",
Expand All @@ -142,14 +139,13 @@
" projected = styled({'Image': dict(plot=dict(projection=projection))}) if projection else styled\n",
" return (projected * gv.Feature(cf.COASTLINE)(plot=dict(scale='50m')))\n",
"\n",
"NbParams(CubeBrowser, execute='next')"
"Widgets(CubeBrowser, next_n=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"urth": {
"dashboard": {
"layout": {
Expand Down Expand Up @@ -289,21 +285,9 @@
},
"hide_input": false,
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
"name": "python3"
},
"urth": {
"dashboard": {
Expand All @@ -315,5 +299,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

0 comments on commit 056a908

Please sign in to comment.