diff --git a/README.md b/README.md index 64b3a70..ce029c6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# dash-canvas +# dash-canvas [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/plotly/dash-canvas/master?urlpath=apps%2Fbinder%2Fcorrect_segmentation.ipynb) dash-canvas is a package for image processing with [Dash](https://dash.plot.ly/). It provides a Dash component for diff --git a/binder/correct_segmentation.ipynb b/binder/correct_segmentation.ipynb new file mode 100644 index 0000000..c2e8ae7 --- /dev/null +++ b/binder/correct_segmentation.ipynb @@ -0,0 +1,165 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Segmentation Correction App\n", + "Here we show a simple segmentation correction app using the [dash-canvas](https://github.com/plotly/dash-canvas) tool." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from IPython import display\n", + "import os\n", + "def show_app(app, port = 9999, \n", + " width = \"100%\", \n", + " height = \"900px\", \n", + " offline = False,\n", + " in_binder = None):\n", + " in_binder ='JUPYTERHUB_SERVICE_PREFIX' in os.environ if in_binder is None else in_binder\n", + " if in_binder:\n", + " base_prefix = '{}proxy/{}/'.format(os.environ['JUPYTERHUB_SERVICE_PREFIX'], port)\n", + " url = 'https://hub.mybinder.org{}'.format(base_prefix)\n", + " app.config.requests_pathname_prefix = base_prefix\n", + " else:\n", + " url = 'http://localhost:%d' % port\n", + " \n", + " iframe = 'Open in new window
'.format(url = url, \n", + " width = width, \n", + " height = height)\n", + " \n", + " display.display_html(iframe, raw = True)\n", + " if offline:\n", + " app.css.config.serve_locally = True\n", + " app.scripts.config.serve_locally = True\n", + " return app.run_server(debug=False, # needs to be false in Jupyter\n", + " host = '0.0.0.0',\n", + " port=port)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import os, sys\n", + "sys.path.append('..')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/srv/conda/lib/python3.6/site-packages/skimage/util/dtype.py:141: UserWarning:\n", + "\n", + "Possible precision loss when converting from float64 to uint8\n", + "\n" + ] + } + ], + "source": [ + "import dash\n", + "import app2_correct_segmentation as cs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "Open in new window
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * Serving Flask app \"CorrectSegmentation\" (lazy loading)\n", + " * Environment: production\n", + " WARNING: Do not use the development server in a production environment.\n", + " Use a production WSGI server instead.\n", + " * Debug mode: off\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + " * Running on http://0.0.0.0:9999/ (Press CTRL+C to quit)\n", + "127.0.0.1 - - [02/Apr/2019 16:51:10] \"GET / HTTP/1.1\" 200 -\n", + "127.0.0.1 - - [02/Apr/2019 16:51:10] \"GET /_dash-dependencies HTTP/1.1\" 200 -\n", + "127.0.0.1 - - [02/Apr/2019 16:51:10] \"GET /_dash-layout HTTP/1.1\" 200 -\n", + "127.0.0.1 - - [02/Apr/2019 16:51:11] \"POST /_dash-update-component HTTP/1.1\" 200 -\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "updating\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "127.0.0.1 - - [02/Apr/2019 16:51:11] \"POST /_dash-update-component HTTP/1.1\" 200 -\n", + "127.0.0.1 - - [02/Apr/2019 16:51:12] \"POST /_dash-update-component HTTP/1.1\" 200 -\n", + "127.0.0.1 - - [02/Apr/2019 16:51:12] \"POST /_dash-update-component HTTP/1.1\" 200 -\n" + ] + } + ], + "source": [ + "app = dash.Dash('CorrectSegmentation')\n", + "app.layout = cs.layout\n", + "cs.callbacks(app)\n", + "show_app(app)" + ] + }, + { + "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.7" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/binder/environment.yml b/binder/environment.yml new file mode 100644 index 0000000..c08e9c9 --- /dev/null +++ b/binder/environment.yml @@ -0,0 +1,20 @@ +name: dash_canvas +channels: + - plotly + - conda-forge + - defaults +dependencies: + - python=3.6 + - numpy + - pandas + - matplotlib + - nbserverproxy + - appmode + - scikit-learn + - scikit-image + - notebook + - dash==0.39.0 # The core dash backend + - plotly==3.7.1 # Plotly graphing library used in examples + - dash-daq==0.1.0 # DAQ components (newly open-sourced!) + - pip: + - dash-canvas diff --git a/binder/segmentation.ipynb b/binder/segmentation.ipynb new file mode 100644 index 0000000..1e16b91 --- /dev/null +++ b/binder/segmentation.ipynb @@ -0,0 +1,143 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Segmentation App\n", + "Here we show a simple segmentation app using the [dash-canvas](https://github.com/plotly/dash-canvas) tool." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "from IPython import display\n", + "import os\n", + "def show_app(app, port = 9999, \n", + " width = \"100%\", \n", + " height = \"900px\", \n", + " offline = False,\n", + " in_binder = None):\n", + " in_binder ='JUPYTERHUB_SERVICE_PREFIX' in os.environ if in_binder is None else in_binder\n", + " if in_binder:\n", + " base_prefix = '{}proxy/{}/'.format(os.environ['JUPYTERHUB_SERVICE_PREFIX'], port)\n", + " url = 'https://hub.mybinder.org{}'.format(base_prefix)\n", + " app.config.requests_pathname_prefix = base_prefix\n", + " else:\n", + " url = 'http://localhost:%d' % port\n", + " \n", + " iframe = 'Open in new window
'.format(url = url, \n", + " width = width, \n", + " height = height)\n", + " \n", + " display.display_html(iframe, raw = True)\n", + " if offline:\n", + " app.css.config.serve_locally = True\n", + " app.scripts.config.serve_locally = True\n", + " return app.run_server(debug=False, # needs to be false in Jupyter\n", + " host = '0.0.0.0',\n", + " port=port)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import os, sys\n", + "sys.path.append('..')" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "import dash\n", + "import app1_seg as seg" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "Open in new window
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + " * Serving Flask app \"Segmentation\" (lazy loading)\n", + " * Environment: production\n", + " WARNING: Do not use the development server in a production environment.\n", + " Use a production WSGI server instead.\n", + " * Debug mode: off\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + " * Running on http://0.0.0.0:9999/ (Press CTRL+C to quit)\n", + "127.0.0.1 - - [02/Apr/2019 16:52:36] \"GET / HTTP/1.1\" 200 -\n", + "127.0.0.1 - - [02/Apr/2019 16:52:37] \"GET /_dash-dependencies HTTP/1.1\" 200 -\n", + "127.0.0.1 - - [02/Apr/2019 16:52:39] \"GET /_dash-layout HTTP/1.1\" 200 -\n", + "127.0.0.1 - - [02/Apr/2019 16:52:39] \"POST /_dash-update-component HTTP/1.1\" 204 -\n", + "127.0.0.1 - - [02/Apr/2019 16:52:39] \"POST /_dash-update-component HTTP/1.1\" 204 -\n", + "127.0.0.1 - - [02/Apr/2019 16:52:39] \"POST /_dash-update-component HTTP/1.1\" 204 -\n", + "127.0.0.1 - - [02/Apr/2019 16:52:47] \"POST /_dash-update-component HTTP/1.1\" 200 -\n", + "127.0.0.1 - - [02/Apr/2019 16:52:59] \"POST /_dash-update-component HTTP/1.1\" 200 -\n", + "127.0.0.1 - - [02/Apr/2019 16:53:09] \"POST /_dash-update-component HTTP/1.1\" 200 -\n" + ] + } + ], + "source": [ + "app = dash.Dash('Segmentation')\n", + "app.layout = seg.layout\n", + "seg.callbacks(app)\n", + "show_app(app)" + ] + }, + { + "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.7" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}