{"action":"created","issue":{"url":"https://api.github.com/repos/hyperspy/hyperspy/issues/773","labels_url":"https://api.github.com/repos/hyperspy/hyperspy/issues/773/labels{/name}","comments_url":"https://api.github.com/repos/hyperspy/hyperspy/issues/773/comments","events_url":"https://api.github.com/repos/hyperspy/hyperspy/issues/773/events","html_url":"https://github.com/hyperspy/hyperspy/issues/773","id":120201066,"number":773,"title":"Model interactive widgets","user":{"login":"to266","id":3384140,"avatar_url":"https://avatars.githubusercontent.com/u/3384140?v=3","gravatar_id":"","url":"https://api.github.com/users/to266","html_url":"https://github.com/to266","followers_url":"https://api.github.com/users/to266/followers","following_url":"https://api.github.com/users/to266/following{/other_user}","gists_url":"https://api.github.com/users/to266/gists{/gist_id}","starred_url":"https://api.github.com/users/to266/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/to266/subscriptions","organizations_url":"https://api.github.com/users/to266/orgs","repos_url":"https://api.github.com/users/to266/repos","events_url":"https://api.github.com/users/to266/events{/privacy}","received_events_url":"https://api.github.com/users/to266/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hyperspy/hyperspy/labels/enhancement","name":"enhancement","color":"02e10c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-03T15:46:46Z","updated_at":"2015-12-03T16:13:44Z","closed_at":null,"body":"I was playing with models and figured it's relatively simple to add interactive widgets to a model:\r\n\r\n```python\r\nfrom IPython.html.widgets import interact\r\nfrom IPython.html import widgets\r\n\r\ndef create_kwargs(comp):\r\n    \r\n    def figure_out_bounds(param):\r\n        fraction = 10.\r\n        _min, _max = None, None\r\n        if param.bmin is not None:\r\n            _min = param.bmin\r\n        if param.bmax is not None:\r\n            _max = param.bmax\r\n        if _max is None and _min is not None:\r\n            _max = param.value + fraction*(param.value - _min)\r\n        if _min is None and _max is not None:\r\n            _min = param.value - fraction*(_max - param.value)\r\n        if _min is None and _max is None:\r\n            _min = param.value / fraction\r\n            _max = param.value * fraction\r\n        step = (_max - _min)*0.001\r\n        return {'min' : _min, 'max' : _max, 'step' : step}\r\n    kwargs = {par._id_name: widgets.FloatSlider(value = par.value, **figure_out_bounds(par)) for par in comp.parameters}\r\n    return kwargs\r\n\r\ndef interactive_sliders(model):\r\n    \r\n    def get_update_model_func(comp):        \r\n        def update_model(**kwargs):\r\n            for k, v in kwargs.iteritems():\r\n                getattr(comp, k).value = v\r\n        return update_model\r\n    \r\n    for component in model:\r\n        interact(get_update_model_func(component), **create_kwargs(component))\r\n```\r\n\r\nThe code is not elegant or general or a number of other things, but seems to work.\r\n\r\nThere is an issue with very small values for floats, though: https://github.com/ipython/ipywidgets/issues/259\r\n\r\nDo you think something similar, in-built into hyperspy would be useful?"},"comment":{"url":"https://api.github.com/repos/hyperspy/hyperspy/issues/comments/161695340","html_url":"https://github.com/hyperspy/hyperspy/issues/773#issuecomment-161695340","issue_url":"https://api.github.com/repos/hyperspy/hyperspy/issues/773","id":161695340,"user":{"login":"to266","id":3384140,"avatar_url":"https://avatars.githubusercontent.com/u/3384140?v=3","gravatar_id":"","url":"https://api.github.com/users/to266","html_url":"https://github.com/to266","followers_url":"https://api.github.com/users/to266/followers","following_url":"https://api.github.com/users/to266/following{/other_user}","gists_url":"https://api.github.com/users/to266/gists{/gist_id}","starred_url":"https://api.github.com/users/to266/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/to266/subscriptions","organizations_url":"https://api.github.com/users/to266/orgs","repos_url":"https://api.github.com/users/to266/repos","events_url":"https://api.github.com/users/to266/events{/privacy}","received_events_url":"https://api.github.com/users/to266/received_events","type":"User","site_admin":false},"created_at":"2015-12-03T16:13:44Z","updated_at":"2015-12-03T16:13:44Z","body":"I'm not experienced enough with how we do that. I think the most difficult part is navigators and interactive range selector things..? \r\n\r\nAny way, in the ipywidgets gitter I also found this:\r\nhttp://mybinder.org/repo/sylvaincorlay/bqplot-binder\r\n\r\nLooks impressive :)"}}