{"action":"opened","number":171,"pull_request":{"url":"https://api.github.com/repos/ramnathv/htmlwidgets/pulls/171","id":51868690,"html_url":"https://github.com/ramnathv/htmlwidgets/pull/171","diff_url":"https://github.com/ramnathv/htmlwidgets/pull/171.diff","patch_url":"https://github.com/ramnathv/htmlwidgets/pull/171.patch","issue_url":"https://api.github.com/repos/ramnathv/htmlwidgets/issues/171","number":171,"state":"open","locked":false,"title":"Introduce new-style instance-bound widget definitions","user":{"login":"jcheng5","id":129551,"avatar_url":"https://avatars.githubusercontent.com/u/129551?v=3","gravatar_id":"","url":"https://api.github.com/users/jcheng5","html_url":"https://github.com/jcheng5","followers_url":"https://api.github.com/users/jcheng5/followers","following_url":"https://api.github.com/users/jcheng5/following{/other_user}","gists_url":"https://api.github.com/users/jcheng5/gists{/gist_id}","starred_url":"https://api.github.com/users/jcheng5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcheng5/subscriptions","organizations_url":"https://api.github.com/users/jcheng5/orgs","repos_url":"https://api.github.com/users/jcheng5/repos","events_url":"https://api.github.com/users/jcheng5/events{/privacy}","received_events_url":"https://api.github.com/users/jcheng5/received_events","type":"User","site_admin":false},"body":"This is part 1 of letting users add arbitrary JS to orchestrate htmlwidget components. Up until now we have mostly focused on inserting a visualization into a page and being done--the only times any code from outside the visualization interacts with that visualization again, is if 1) the container is resized, then we call resize(); and 2) in Shiny contexts, new data can be provided and renderValue() gets called again in that case.\r\n\r\nWhat I would like to allow going forward is arbitrary interaction with htmlwidget components from code outside of the component. You should be able to have your widget expose whatever methods you want, and it should be easy to call those components from JavaScript running elsewhere in the page.\r\n\r\nFor this to happen we need two things to happen.\r\n\r\n1. It needs to be easy and natural for htmlwidget authors to add custom methods that can be invoked on a widget instance. This was not easy nor natural in the past, because the object that you pass into `HTMLWidgets.widget()` was a single object that was responsible for all widget instances of that type. (This also led to an awkward programming style in general.) This PR changes this to one-object-per-widget-instance.\r\n2. You need to be able to easily specify an ID for a widget, and then use that ID from JavaScript to access the widget instance (like `HTMLWidgets.get(id)`). This will be introduced in a separate PR.\r\n\r\nOnce both items are in place you'll be able to do something like this (assuming appropriate support in the widgets themselves:\r\n\r\n```r\r\nwidgetGridPage(\r\n  widget1(id = \"one\", data = iris, ...),\r\n  widget2(id = \"two\", data = iris, ...),\r\n  tags$script(\"\r\n    HTMLWidgets.get('one').on('bounds-changed', function(e) {\r\n      HTMLWidgets.get('two').setBounds(e.value);\r\n    });\r\n  \")\r\n)\r\n```\r\n\r\nTake a look at the difference between these two otherwise-identical bindings to see the contrast between the existing class-bound definitions and the new instance-bound definitions.\r\n\r\n[Class-bound](https://github.com/jcheng5/d3scatter/blob/94e512f6edc15a4ac122e61136e1d40ca6ff8a6e/inst/htmlwidgets/d3scatter.js)\r\n[Instance-bound](https://github.com/jcheng5/d3scatter/blob/470c571f48e6fe895bc2af4bc3cc159d8df63cbe/inst/htmlwidgets/d3scatter.js)\r\n\r\nThis particular instance-bound example doesn't do anything besides support `renderValue` and `resize`, but you could imagine any number of properties and methods added to that object.","created_at":"2015-11-26T03:15:19Z","updated_at":"2015-11-26T03:15:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ramnathv/htmlwidgets/pulls/171/commits","review_comments_url":"https://api.github.com/repos/ramnathv/htmlwidgets/pulls/171/comments","review_comment_url":"https://api.github.com/repos/ramnathv/htmlwidgets/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ramnathv/htmlwidgets/issues/171/comments","statuses_url":"https://api.github.com/repos/ramnathv/htmlwidgets/statuses/399c86cb2d676aa7d9960ea31e43a897962410e1","head":{"label":"ramnathv:joe/feature/instance-bound","ref":"joe/feature/instance-bound","sha":"399c86cb2d676aa7d9960ea31e43a897962410e1","user":{"login":"ramnathv","id":346288,"avatar_url":"https://avatars.githubusercontent.com/u/346288?v=3","gravatar_id":"","url":"https://api.github.com/users/ramnathv","html_url":"https://github.com/ramnathv","followers_url":"https://api.github.com/users/ramnathv/followers","following_url":"https://api.github.com/users/ramnathv/following{/other_user}","gists_url":"https://api.github.com/users/ramnathv/gists{/gist_id}","starred_url":"https://api.github.com/users/ramnathv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramnathv/subscriptions","organizations_url":"https://api.github.com/users/ramnathv/orgs","repos_url":"https://api.github.com/users/ramnathv/repos","events_url":"https://api.github.com/users/ramnathv/events{/privacy}","received_events_url":"https://api.github.com/users/ramnathv/received_events","type":"User","site_admin":false},"repo":{"id":21957161,"name":"htmlwidgets","full_name":"ramnathv/htmlwidgets","owner":{"login":"ramnathv","id":346288,"avatar_url":"https://avatars.githubusercontent.com/u/346288?v=3","gravatar_id":"","url":"https://api.github.com/users/ramnathv","html_url":"https://github.com/ramnathv","followers_url":"https://api.github.com/users/ramnathv/followers","following_url":"https://api.github.com/users/ramnathv/following{/other_user}","gists_url":"https://api.github.com/users/ramnathv/gists{/gist_id}","starred_url":"https://api.github.com/users/ramnathv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramnathv/subscriptions","organizations_url":"https://api.github.com/users/ramnathv/orgs","repos_url":"https://api.github.com/users/ramnathv/repos","events_url":"https://api.github.com/users/ramnathv/events{/privacy}","received_events_url":"https://api.github.com/users/ramnathv/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ramnathv/htmlwidgets","description":"HTML Widgets for R","fork":false,"url":"https://api.github.com/repos/ramnathv/htmlwidgets","forks_url":"https://api.github.com/repos/ramnathv/htmlwidgets/forks","keys_url":"https://api.github.com/repos/ramnathv/htmlwidgets/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ramnathv/htmlwidgets/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ramnathv/htmlwidgets/teams","hooks_url":"https://api.github.com/repos/ramnathv/htmlwidgets/hooks","issue_events_url":"https://api.github.com/repos/ramnathv/htmlwidgets/issues/events{/number}","events_url":"https://api.github.com/repos/ramnathv/htmlwidgets/events","assignees_url":"https://api.github.com/repos/ramnathv/htmlwidgets/assignees{/user}","branches_url":"https://api.github.com/repos/ramnathv/htmlwidgets/branches{/branch}","tags_url":"https://api.github.com/repos/ramnathv/htmlwidgets/tags","blobs_url":"https://api.github.com/repos/ramnathv/htmlwidgets/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ramnathv/htmlwidgets/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ramnathv/htmlwidgets/git/refs{/sha}","trees_url":"https://api.github.com/repos/ramnathv/htmlwidgets/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ramnathv/htmlwidgets/statuses/{sha}","languages_url":"https://api.github.com/repos/ramnathv/htmlwidgets/languages","stargazers_url":"https://api.github.com/repos/ramnathv/htmlwidgets/stargazers","contributors_url":"https://api.github.com/repos/ramnathv/htmlwidgets/contributors","subscribers_url":"https://api.github.com/repos/ramnathv/htmlwidgets/subscribers","subscription_url":"https://api.github.com/repos/ramnathv/htmlwidgets/subscription","commits_url":"https://api.github.com/repos/ramnathv/htmlwidgets/commits{/sha}","git_commits_url":"https://api.github.com/repos/ramnathv/htmlwidgets/git/commits{/sha}","comments_url":"https://api.github.com/repos/ramnathv/htmlwidgets/comments{/number}","issue_comment_url":"https://api.github.com/repos/ramnathv/htmlwidgets/issues/comments{/number}","contents_url":"https://api.github.com/repos/ramnathv/htmlwidgets/contents/{+path}","compare_url":"https://api.github.com/repos/ramnathv/htmlwidgets/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ramnathv/htmlwidgets/merges","archive_url":"https://api.github.com/repos/ramnathv/htmlwidgets/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ramnathv/htmlwidgets/downloads","issues_url":"https://api.github.com/repos/ramnathv/htmlwidgets/issues{/number}","pulls_url":"https://api.github.com/repos/ramnathv/htmlwidgets/pulls{/number}","milestones_url":"https://api.github.com/repos/ramnathv/htmlwidgets/milestones{/number}","notifications_url":"https://api.github.com/repos/ramnathv/htmlwidgets/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ramnathv/htmlwidgets/labels{/name}","releases_url":"https://api.github.com/repos/ramnathv/htmlwidgets/releases{/id}","created_at":"2014-07-17T20:49:59Z","updated_at":"2015-11-25T20:07:54Z","pushed_at":"2015-11-26T02:33:07Z","git_url":"git://github.com/ramnathv/htmlwidgets.git","ssh_url":"git@github.com:ramnathv/htmlwidgets.git","clone_url":"https://github.com/ramnathv/htmlwidgets.git","svn_url":"https://github.com/ramnathv/htmlwidgets","homepage":"http://htmlwidgets.org","size":6205,"stargazers_count":313,"watchers_count":313,"language":"R","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":75,"mirror_url":null,"open_issues_count":39,"forks":75,"open_issues":39,"watchers":313,"default_branch":"master"}},"base":{"label":"ramnathv:master","ref":"master","sha":"c219c3fd98ad312bcca5e4b68d9b8ad9b4f286a0","user":{"login":"ramnathv","id":346288,"avatar_url":"https://avatars.githubusercontent.com/u/346288?v=3","gravatar_id":"","url":"https://api.github.com/users/ramnathv","html_url":"https://github.com/ramnathv","followers_url":"https://api.github.com/users/ramnathv/followers","following_url":"https://api.github.com/users/ramnathv/following{/other_user}","gists_url":"https://api.github.com/users/ramnathv/gists{/gist_id}","starred_url":"https://api.github.com/users/ramnathv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramnathv/subscriptions","organizations_url":"https://api.github.com/users/ramnathv/orgs","repos_url":"https://api.github.com/users/ramnathv/repos","events_url":"https://api.github.com/users/ramnathv/events{/privacy}","received_events_url":"https://api.github.com/users/ramnathv/received_events","type":"User","site_admin":false},"repo":{"id":21957161,"name":"htmlwidgets","full_name":"ramnathv/htmlwidgets","owner":{"login":"ramnathv","id":346288,"avatar_url":"https://avatars.githubusercontent.com/u/346288?v=3","gravatar_id":"","url":"https://api.github.com/users/ramnathv","html_url":"https://github.com/ramnathv","followers_url":"https://api.github.com/users/ramnathv/followers","following_url":"https://api.github.com/users/ramnathv/following{/other_user}","gists_url":"https://api.github.com/users/ramnathv/gists{/gist_id}","starred_url":"https://api.github.com/users/ramnathv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramnathv/subscriptions","organizations_url":"https://api.github.com/users/ramnathv/orgs","repos_url":"https://api.github.com/users/ramnathv/repos","events_url":"https://api.github.com/users/ramnathv/events{/privacy}","received_events_url":"https://api.github.com/users/ramnathv/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ramnathv/htmlwidgets","description":"HTML Widgets for R","fork":false,"url":"https://api.github.com/repos/ramnathv/htmlwidgets","forks_url":"https://api.github.com/repos/ramnathv/htmlwidgets/forks","keys_url":"https://api.github.com/repos/ramnathv/htmlwidgets/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ramnathv/htmlwidgets/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ramnathv/htmlwidgets/teams","hooks_url":"https://api.github.com/repos/ramnathv/htmlwidgets/hooks","issue_events_url":"https://api.github.com/repos/ramnathv/htmlwidgets/issues/events{/number}","events_url":"https://api.github.com/repos/ramnathv/htmlwidgets/events","assignees_url":"https://api.github.com/repos/ramnathv/htmlwidgets/assignees{/user}","branches_url":"https://api.github.com/repos/ramnathv/htmlwidgets/branches{/branch}","tags_url":"https://api.github.com/repos/ramnathv/htmlwidgets/tags","blobs_url":"https://api.github.com/repos/ramnathv/htmlwidgets/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ramnathv/htmlwidgets/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ramnathv/htmlwidgets/git/refs{/sha}","trees_url":"https://api.github.com/repos/ramnathv/htmlwidgets/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ramnathv/htmlwidgets/statuses/{sha}","languages_url":"https://api.github.com/repos/ramnathv/htmlwidgets/languages","stargazers_url":"https://api.github.com/repos/ramnathv/htmlwidgets/stargazers","contributors_url":"https://api.github.com/repos/ramnathv/htmlwidgets/contributors","subscribers_url":"https://api.github.com/repos/ramnathv/htmlwidgets/subscribers","subscription_url":"https://api.github.com/repos/ramnathv/htmlwidgets/subscription","commits_url":"https://api.github.com/repos/ramnathv/htmlwidgets/commits{/sha}","git_commits_url":"https://api.github.com/repos/ramnathv/htmlwidgets/git/commits{/sha}","comments_url":"https://api.github.com/repos/ramnathv/htmlwidgets/comments{/number}","issue_comment_url":"https://api.github.com/repos/ramnathv/htmlwidgets/issues/comments{/number}","contents_url":"https://api.github.com/repos/ramnathv/htmlwidgets/contents/{+path}","compare_url":"https://api.github.com/repos/ramnathv/htmlwidgets/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ramnathv/htmlwidgets/merges","archive_url":"https://api.github.com/repos/ramnathv/htmlwidgets/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ramnathv/htmlwidgets/downloads","issues_url":"https://api.github.com/repos/ramnathv/htmlwidgets/issues{/number}","pulls_url":"https://api.github.com/repos/ramnathv/htmlwidgets/pulls{/number}","milestones_url":"https://api.github.com/repos/ramnathv/htmlwidgets/milestones{/number}","notifications_url":"https://api.github.com/repos/ramnathv/htmlwidgets/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ramnathv/htmlwidgets/labels{/name}","releases_url":"https://api.github.com/repos/ramnathv/htmlwidgets/releases{/id}","created_at":"2014-07-17T20:49:59Z","updated_at":"2015-11-25T20:07:54Z","pushed_at":"2015-11-26T02:33:07Z","git_url":"git://github.com/ramnathv/htmlwidgets.git","ssh_url":"git@github.com:ramnathv/htmlwidgets.git","clone_url":"https://github.com/ramnathv/htmlwidgets.git","svn_url":"https://github.com/ramnathv/htmlwidgets","homepage":"http://htmlwidgets.org","size":6205,"stargazers_count":313,"watchers_count":313,"language":"R","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":75,"mirror_url":null,"open_issues_count":39,"forks":75,"open_issues":39,"watchers":313,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ramnathv/htmlwidgets/pulls/171"},"html":{"href":"https://github.com/ramnathv/htmlwidgets/pull/171"},"issue":{"href":"https://api.github.com/repos/ramnathv/htmlwidgets/issues/171"},"comments":{"href":"https://api.github.com/repos/ramnathv/htmlwidgets/issues/171/comments"},"review_comments":{"href":"https://api.github.com/repos/ramnathv/htmlwidgets/pulls/171/comments"},"review_comment":{"href":"https://api.github.com/repos/ramnathv/htmlwidgets/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ramnathv/htmlwidgets/pulls/171/commits"},"statuses":{"href":"https://api.github.com/repos/ramnathv/htmlwidgets/statuses/399c86cb2d676aa7d9960ea31e43a897962410e1"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":39,"deletions":0,"changed_files":1}}