') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Add Binder Link by kmader · Pull Request #16 · plotly/dash-canvas · GitHub
Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line numberDiff line numberDiff line change
@@ -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
Expand Down
165 changes: 165 additions & 0 deletions binder/correct_segmentation.ipynb
Original file line numberDiff line numberDiff line change
@@ -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 = '<a href=\"{url}\" target=\"_new\">Open in new window</a><hr><iframe src=\"{url}\" width={width} height={height}></iframe>'.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": [
"<a href=\"https://hub.mybinder.org/user/kmader-dash-canvas-ivyrnudq/proxy/9999/\" target=\"_new\">Open in new window</a><hr><iframe src=\"https://hub.mybinder.org/user/kmader-dash-canvas-ivyrnudq/proxy/9999/\" width=100% height=900px></iframe>"
]
},
"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
}
20 changes: 20 additions & 0 deletions binder/environment.yml
Original file line numberDiff line numberDiff line change
@@ -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
143 changes: 143 additions & 0 deletions binder/segmentation.ipynb
Original file line numberDiff line numberDiff line change
@@ -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 = '<a href=\"{url}\" target=\"_new\">Open in new window</a><hr><iframe src=\"{url}\" width={width} height={height}></iframe>'.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": [
"<a href=\"https://hub.mybinder.org/user/kmader-dash-canvas-ivyrnudq/proxy/9999/\" target=\"_new\">Open in new window</a><hr><iframe src=\"https://hub.mybinder.org/user/kmader-dash-canvas-ivyrnudq/proxy/9999/\" width=100% height=900px></iframe>"
]
},
"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
}