title: How to implement a tab generator with interactive buttons?
body: <p>My app has a button for creating new tabs. Each new tab has itself a button. When I add <code>on_click</code> to that button I get a error handling message:</p>
  
  <blockquote>
    <p>error handling message Message 'EVENT' (revision 1) content: '{"event_name":"button_click","event_values":{"model_id":"1002"}}': RuntimeError('Set changed size during iteration',)</p>
  </blockquote>
  
  <p>Here is a minimal example that causes the error message.</p>
  
  <pre class="lang-py prettyprint-override"><code>from bokeh.models import Panel, Tabs, Button
  from bokeh.plotting import curdoc
  
  def print_stuff():
      print('stuff')
  
  def create_new_tab():
  
      button = Button(label='click me')
      button.on_click(print_stuff)
      tab = Panel(child=button, title="tab")
  
      return tab
  
  def append_new_tab():
      new_tab = create_new_tab()
      curdoc().select_one({'name': 'tabs'}).tabs.append(new_tab)
  
  button = Button(label='append new tab')
  button.on_click(append_new_tab)
  
  tab1 = Panel(child=button, title='button tab')
  tabs = Tabs(tabs = [tab1], name='tabs')
  
  curdoc().add_root(tabs)
  </code></pre>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Which set changes during iteration?</li>
  <li>During what iteration?</li>
  <li>How to fix this?</li>
  </ol>
  
  <p>Background:
  Tab 1 is a configuration tab with several input widgets. The <code>append new tab</code> button creates a tab with several data plots that are generated using the input widgets. These plots have themselves buttons.</p>