{"id":84,"date":"2020-07-29T08:10:48","date_gmt":"2020-07-29T13:10:48","guid":{"rendered":"https:\/\/www.grizzly-hills.com\/?p=84"},"modified":"2020-07-29T08:10:48","modified_gmt":"2020-07-29T13:10:48","slug":"jupyter-widgets-finding-my-cell-object","status":"publish","type":"post","link":"https:\/\/www.grizzly-hills.com\/index.php\/2020\/07\/29\/jupyter-widgets-finding-my-cell-object\/","title":{"rendered":"Jupyter Widgets: Finding My Cell Object"},"content":{"rendered":"\n<p>When writing a custom Jupyter Widget, sometimes you need to know the Cell (CodeCell, usually) that your Widget is running in. You can get a list of all Cells from the Notebook object in Javascript, but finding your Cell isn&#8217;t exactly that straight-forward.<\/p>\n\n\n<p>Fortunately, it isn&#8217;t that hard to determine your Cell, since you can find the container element for your Widget, and then loop through all Cells in the Notebook to see which one you are in:<\/p>\n\n\n<pre class=\"wp-block-preformatted\">const container = this.$el.parents('.cell');\nconst cell = this.notebook.get_cells().find(it =&gt; it.element.is(container));<\/pre>\n\n\n<p>If all goes well, <code>cell<\/code> will contain your Cell object.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When writing a custom Jupyter Widget, sometimes you need to know the Cell (CodeCell, usually) that your Widget is running in. You can get a list of all Cells from the Notebook object in Javascript, but finding your Cell isn&#8217;t exactly that straight-forward. Fortunately, it isn&#8217;t that hard to determine your Cell, since you can &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.grizzly-hills.com\/index.php\/2020\/07\/29\/jupyter-widgets-finding-my-cell-object\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Jupyter Widgets: Finding My Cell Object&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[12,15],"class_list":["post-84","post","type-post","status-publish","format-standard","hentry","category-coding","category-jupyter-extensions","tag-javascript","tag-jupyter"],"_links":{"self":[{"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/posts\/84","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":0,"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.grizzly-hills.com\/index.php\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}