title: ipywidgets button on click run next widget
body: <p>I am building a small Jupyter Notebook widget to call a Rest API and get some data.
  The user need to provide an auth token to be able to call the API. The auth token (JWT Token) will be provided to the user from a different interface. The API will respond with a json list of data which needs to be put into a combobox and then user can choose 1 which will be inserted into a new cell</p>
  <p>The issue I am running into is that I am unable to tell the API call to wait for user to input the auth token and click on the submit button.</p>
  <p>There are 2 actions happening here</p>
  <p>Act 1 : Text Box and Button for the auth token. User puts the auth token in the text box and clicks submit.</p>
  <p>Auth token gets put into a global variable by the button on clicked function</p>
  <p>Act 2: Use the global variable to call the Rest API to get the JSON list of data</p>
  <p>Put the list into a combobox</p>
  <p>User chooses a specific value.</p>
  <p>Dump that specific data into a new cell</p>
  <pre><code>import requests
  import json
  from IPython.display import Javascript, display
  
  def click_get_auth_token(b):
      global get_datasources_api_token
      get_datasources_api_token = atok.value
      return None
  
  def show_wid():
      global atok
      atok = widgets.Text(
          placeholder='Auth_Token',
          description='Auth Token',
          disabled=False
      )
      display(atok)
      button = widgets.Button(description=&quot;Submit&quot;)
      display(button)
      button.on_click(click_get_auth_token)
      return None
  
  def click_get_auth_token():
      show_wid()
      headers = {}
      resp = requests.get('http://localhost:5000/get_data', headers={&quot;Authorization&quot; : &quot;Bearer &quot; + get_datasources_api_token})
      resp = resp.json()
      dsr_list = resp['datasources']
      opt_list = []
      for dsr in dsr_list:
          opt_list.append(dsr[&quot;name&quot;])
      print(opt_list)
      global w
      w = widgets.Combobox(
          options= opt_list,
          disabled=False,
          ensure_option=True,
      )
      display(w)
      button = widgets.Button(description=&quot;Get Data&quot;)
      display(button)
      button.on_click(click_get_datasources)
  def click_get_datasources()
      dataset = None
      for dsr in dsr_list:
          if(dsr[&quot;name&quot;] == w.value):
              dataset = dsr
      encoded_code = (base64.b64encode(str.encode(dataset))).decode()
      display(Javascript(&quot;&quot;&quot;
          var code = IPython.notebook.insert_cell_below('code');
          code.set_text(atob(&quot;{0}&quot;));
      &quot;&quot;&quot;.format(encoded_code)))
  </code></pre>
  <p>My code is probably all over the place and is needlessly complex.</p>
  <p>At the moment it works as long as I hard code an auth token.
  But I am unable to get the Rest call to wait for the user to paste the token.</p>
  <p>Any help would be appreciated.</p>
  <p>Thank you</p>