Skip to content

Add support for ipywidgets#10606

Merged
DonJayamanne merged 6 commits intomicrosoft:ds/ipyWidgetsfrom
DonJayamanne:myCOpy
Mar 17, 2020
Merged

Add support for ipywidgets#10606
DonJayamanne merged 6 commits intomicrosoft:ds/ipyWidgetsfrom
DonJayamanne:myCOpy

Conversation

@DonJayamanne
Copy link
Copy Markdown

@DonJayamanne DonJayamanne commented Mar 17, 2020

@rchiodo Here's a demo of it working

  • Attached is a sample ipynb i used for testing (beakerx and others used to work, hopefully they still do) 🤞
  • Simple widgets working
  • Events on client side working
  • Events sending messages to kernel working (last demo is execution of python code when UI state changes).
  • There are know bugs (I got an error message iopub not defined in undefined - obviously due to the changes in master since the last prototype).
  • My suggestion is we merge this PR as is:
    • Work on fixing/refactoring/replacing stuff bit by bit (this way we know what breaks, vs trying to bring things back together and figure out what works and what doesn't..)
    • Before we merge back to master, ensure we review everything and merge (easy to identify by reviewing a PR...)
    • We can then slowly fix bugs (failures in tests, etc).
  • Or, we can not merge this PR, and pull stuff one by one,
    • The problem is we won't know whether it works, until everything is put to gether 😞 (not a fan due to the complexity of the changes)
    • Highlights the fact that we need good tests for this

widgets

Here's the ipynb:

{
 "nbformat": 4,
 "nbformat_minor": 2,
 "metadata": {
  "language_info": {
   "name": "python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "version": "3.7.6-final"
  },
  "orig_nbformat": 2,
  "file_extension": ".py",
  "mimetype": "text/x-python",
  "name": "python",
  "npconvert_exporter": "python",
  "pygments_lexer": "ipython3",
  "version": 3,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  }
 },
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import ipywidgets as widgets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/plain": "IntSlider(value=0)",
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "212bb05a08524cf6ae6b53dac1b54744"
      }
     },
     "metadata": {}
    }
   ],
   "source": [
    "widgets.IntSlider()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/plain": "Text(value='Hello World!', disabled=True)",
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "49f082208f3b475f9cf176cecec653bc"
      }
     },
     "metadata": {}
    }
   ],
   "source": [
    "widgets.Text(value='Hello World!', disabled=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/plain": "VBox(children=(IntSlider(value=0, continuous_update=False, description='Delayed'), IntText(value=0, descriptio…",
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "bb43fbac077f413fac1f982254a61972"
      }
     },
     "metadata": {}
    }
   ],
   "source": [
    "\n",
    "a = widgets.IntSlider(description=\"Delayed\", continuous_update=False)\n",
    "b = widgets.IntText(description=\"Delayed\", continuous_update=False)\n",
    "c = widgets.IntSlider(description=\"Continuous\", continuous_update=True)\n",
    "d = widgets.IntText(description=\"Continuous\", continuous_update=True)\n",
    "\n",
    "widgets.link((a, 'value'), (b, 'value'))\n",
    "widgets.link((a, 'value'), (c, 'value'))\n",
    "widgets.link((a, 'value'), (d, 'value'))\n",
    "widgets.VBox([a,b,c,d])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/plain": "Label(value='The values of range1 and range2 are synchronized')",
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "9c926f7815c04f1ab52ebe6d01a22b2f"
      }
     },
     "metadata": {}
    },
    {
     "output_type": "display_data",
     "data": {
      "text/plain": "IntSlider(value=1, description='Slider', max=5, min=-5)",
      "application/vnd.jupyter.widget-view+json": {
       "version_major": 2,
       "version_minor": 0,
       "model_id": "0d598d0771024720acfe39cce9653320"
      }
     },
     "metadata": {}
    }
   ],
   "source": [
    "caption = widgets.Label(value='The values of range1 and range2 are synchronized')\n",
    "slider = widgets.IntSlider(min=-5, max=5, value=1, description='Slider')\n",
    "\n",
    "def handle_slider_change(change):\n",
    "    caption.value = 'The slider value is ' + (\n",
    "        'negative' if change.new < 0 else 'nonnegative'\n",
    "    )\n",
    "\n",
    "slider.observe(handle_slider_change, names='value')\n",
    "\n",
    "display(caption, slider)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}

@sonarqubecloud
Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@DonJayamanne DonJayamanne requested a review from rchiodo March 17, 2020 01:01
@rchiodo
Copy link
Copy Markdown

rchiodo commented Mar 17, 2020

Woot! Sounds good to me. Awesome that it works

@rchiodo rchiodo marked this pull request as ready for review March 17, 2020 01:02
Copy link
Copy Markdown

@rchiodo rchiodo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@DonJayamanne
Copy link
Copy Markdown
Author

Awesome that it works

Not sure you noticed. I generally use dark theme, but gif is with light theme (hmmm, wonder why... 🤔 )..

@DonJayamanne DonJayamanne changed the title Bring in stuff related to ipywidgets Add support for ipywidgets Mar 17, 2020
@DonJayamanne DonJayamanne merged commit 164727a into microsoft:ds/ipyWidgets Mar 17, 2020
@DonJayamanne DonJayamanne deleted the myCOpy branch March 17, 2020 01:14
@lock lock Bot locked as resolved and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants