title: Shutting down a plotly-dash server
body: <p>This is a follow-up to this question: <a href="https://stackoverflow.com/questions/15562446/how-to-stop-flask-application-without-using-ctrl-c">How to stop flask application without using ctrl-c</a> . The problem is that I didn't understand some of the terminology in the accepted answer since I'm totally new to this.</p>
  
  <pre><code>import dash
  import dash_core_components as dcc
  import dash_html_components as html
  
  app = dash.Dash()
  
  app.layout = html.Div(children=[
      html.H1(children='Dash Tutorials'),
      dcc.Graph()
  ])
  
  if __name__ == '__main__':
      app.run_server(debug=True)
  </code></pre>
  
  <p>How do I shut this down? My end goal is to run a plotly dashboard on a remote machine, but I'm testing it out on my local machine first.</p>
  
  <p>I guess I'm supposed to "expose an endpoint" (have no idea what that means) via:</p>
  
  <pre><code>from flask import request
  def shutdown_server():
      func = request.environ.get('werkzeug.server.shutdown')
      if func is None:
          raise RuntimeError('Not running with the Werkzeug Server')
      func()
  
  @app.route('/shutdown', methods=['POST'])
  def shutdown():
      shutdown_server()
      return 'Server shutting down...'
  </code></pre>
  
  <p>Where do I include the above code? Is it supposed to be included in the first block of code that I showed (i.e. the code that contains <code>app.run_server</code> command)? Is it supposed to be separate? And then what are the exact steps I need to take to shut down the server when I want?</p>
  
  <p>Finally, are the steps to shut down the server the same whether I run the server on a local or remote machine?</p>
  
  <p>Would really appreciate help!</p>