Skip to content

Instantly share code, notes, and snippets.

@bbartley
Last active August 29, 2015 14:23
Show Gist options
  • Save bbartley/b24aeb1fb52c50698ad5 to your computer and use it in GitHub Desktop.
Save bbartley/b24aeb1fb52c50698ad5 to your computer and use it in GitHub Desktop.
Example of a custom widget for iPython 3.1 notebook
/* Should be placed inside your .ipython/nbextensions folder */
require(["widgets/js/widget", "widgets/js/manager"], function(widget, manager){
console.log('Module loaded');
var CustomPickerView = widget.DOMWidgetView.extend({
// Render the view.
render: function(){
this.$el.text('Hello World!');
},
update: function(options) {
console.log("doing update");
}
});
//manager.WidgetManager.register_widget_view('CustomPickerView', CustomPickerView);
return {CustomPickerView: CustomPickerview};
});
/* Import the CustomWidget into your iPython notebook */
from IPython.html import widgets # Widget definitions
from IPython.display import display # Used to display widgets in the notebook
from IPython.display import Javascript
from IPython.utils.traitlets import Unicode # Used to declare attributes of our widget
class CustomWidget(widgets.DOMWidget):
_view_name = Unicode('CustomPickerView', sync=True)
_view_module = Unicode("nbextensions/CustomWidget", sync=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment