{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Default widgets for modules\n", "\n", "Define an `_ipython_display_` function that takes no arguments to show a default display for the module.\n", "\n", "![image](https://user-images.githubusercontent.com/4236275/45131612-bca6fa00-b15b-11e8-9b0b-76c80d4cbce5.png)\n" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [], "source": [ "%reload_ext deathbeds.__Custom_display_formatting\n", "from deathbeds.__Custom_display_formatting import Row, Column\n", "from pandas import *\n", "from poser import *\n", "import os" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example we'll explore the [Flowers datasets on Kaggle](https://www.kaggle.com/alxmamaev/flowers-recognition/version/2#)." ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [], "source": [ "flowers = λ.Path('data/flowers/').Path.glob('*').map(λ.Path.glob('*')).concat().list().pandas.Series()()\n", "flowers = flowers.apply(str).str.lstrip('data'+os.sep).str.split(os.sep, expand=True).set_index(flowers).rename(columns={\n", " 0:'label', 1: 'type', 2: 'file'})" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [], "source": [ "from IPython.display import display" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "def _ipython_display_():\n", " from ipywidgets import interact\n", " @interact\n", " def _(type=list(flowers.type.unique()), rows=3, columns=4):\n", " display(Column([Row([str(x) for x in flowers[flowers.type.eq(type)].sample(columns).index])\n", " for row in range(rows)])) " ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "4817bf7b6ef048b58bb95790686906aa", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(Dropdown(description='type', options=('daisy', 'dandelion', 'rose', 'sunflower', 'tulip'…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "__import__(__name__)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ " " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "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.6.6" } }, "nbformat": 4, "nbformat_minor": 2 }