code: def build_app(
      url=None,
      reaper_on=True,
      app_root=None,
      additional_templates=None,
      **kwargs,
  ):
      """
      Builds :class:`flask:flask.Flask` application encapsulating endpoints for D-Tale's front-end
  
      :param url: optional parameter which sets the host & root for any internal endpoints (ex: pinging shutdown)
      :type url: str, optional
      :param reaper_on: whether to run auto-reaper subprocess
      :type reaper_on: bool
      :param app_root: Optional path to prepend to the routes of D-Tale. This is used when making use of
                       Jupyterhub server proxy
      :type app_root: str, optional
      :param additional_templates: path(s) to any other jinja templates you would like to load.  This comes into play if
                                   you're embedding D-Tale into your own Flask app
      :type: str, list, optional
      :return: :class:`flask:flask.Flask` application
      :rtype: :class:`dtale.app.DtaleFlask`
      """
  
      app = DtaleFlask(
          "dtale",
          reaper_on=reaper_on,
          static_url_path="/dtale/static",
          url=url,
          instance_relative_config=False,
          app_root=app_root,
      )
      app.config["SECRET_KEY"] = "Dtale"
  
      app.jinja_env.trim_blocks = True
      app.jinja_env.lstrip_blocks = True
  
      if app_root is not None:
          app.config["APPLICATION_ROOT"] = app_root
          app.jinja_env.globals["url_for"] = app.url_for
      app.jinja_env.globals["is_app_root_defined"] = is_app_root_defined
  
      if additional_templates:
          loaders = [app.jinja_loader]
          loaders += [
              jinja2.FileSystemLoader(loc)
              for loc in make_list(additional_templates)
          ]
          my_loader = jinja2.ChoiceLoader(loaders)
          app.jinja_loader = my_loader
  
      app.register_blueprint(dtale)
  
      compress = Compress()
      compress.init_app(app)
  
      def _root():
          return redirect("/dtale/{}".format(head_endpoint()))
  
      @app.route("/")
      def root():
          return _root()
  
      @app.route("/dtale")
      def dtale_base():
          """
          :class:`flask:flask.Flask` routes which redirect to dtale/main
  
          :return: 302 - flask.redirect('/dtale/main')
          """
          return _root()
  
      @app.route("/favicon.ico")
      def favicon():
          """
          :class:`flask:flask.Flask` routes which returns favicon
  
          :return: image/png
          """
          return redirect(
              app.url_for("static", filename="images/favicon.ico")
          )
  
      @app.route("/missing-js")
      def missing_js():
          missing_js_commands = (
              ">> cd [location of your local dtale repo]\n"
              ">> yarn install\n"
              ">> yarn run build  # or 'yarn run watch' if you're trying to develop"
          )
          return render_template(
              "dtale/errors/missing_js.html",
              missing_js_commands=missing_js_commands,
          )
  
      @app.errorhandler(404)
      def page_not_found(e=None):
          """
          :class:`flask:flask.Flask` routes which returns favicon
  
          :param e: exception
          :return: text/html with exception information
          """
          return (
              render_template(
                  "dtale/errors/404.html",
                  page="",
                  error=e,
                  stacktrace=str(traceback.format_exc()),
              ),
              404,
          )
  
      @app.errorhandler(500)
      def internal_server_error(e=None):
          """
          :class:`flask:flask.Flask` route which returns favicon
  
          :param e: exception
          :return: text/html with exception information
          """
          return (
              render_template(
                  "dtale/errors/500.html",
                  page="",
                  error=e,
                  stacktrace=str(traceback.format_exc()),
              ),
              500,
          )
  
      def shutdown_server():
          global ACTIVE_HOST, ACTIVE_PORT
          """
          This function that checks if flask.request.environ['werkzeug.server.shutdown'] exists and
          if so, executes that function
          """
          logger.info("Executing shutdown...")
          func = request.environ.get("werkzeug.server.shutdown")
          if func is None:
              logger.info(
                  "Not running with the Werkzeug Server, exiting by searching gc for BaseWSGIServer"
              )
              import gc
              from werkzeug.serving import BaseWSGIServer
  
              for obj in gc.get_objects():
                  try:
                      if isinstance(obj, BaseWSGIServer):
                          obj.shutdown()
                          break
                  except Exception as e:
                      logger.error(e)
          else:
              func()
          global_state.cleanup()
          ACTIVE_PORT = None
          ACTIVE_HOST = None
  
      @app.route("/shutdown")
      def shutdown():
          """
          :class:`flask:flask.Flask` route for initiating server shutdown
  
          :return: text/html with server shutdown message
          """
          app.clear_reaper()
          shutdown_server()
          return "Server shutting down..."
  
      @app.before_request
      @auth.requires_auth
      def before_request():
          """
          Logic executed before each :attr:`flask:flask.request`
  
          :return: text/html with server shutdown message
          """
          app.build_reaper()
  
      @app.route("/site-map")
      def site_map():
          """
          :class:`flask:flask.Flask` route listing all available flask endpoints
  
          :return: JSON of all flask enpoints [
              [endpoint1, function path1],
              ...,
              [endpointN, function pathN]
          ]
          """
  
          def has_no_empty_params(rule):
              defaults = rule.defaults or ()
              arguments = rule.arguments or ()
              return len(defaults) >= len(arguments)
  
          links = []
          for rule in app.url_map.iter_rules():
              # Filter out rules we can't navigate to in a browser
              # and rules that require parameters
              if "GET" in rule.methods and has_no_empty_params(rule):
                  url = app.url_for(
                      rule.endpoint, **(rule.defaults or {})
                  )
                  links.append((url, rule.endpoint))
          return jsonify(links)
  
      @app.route("/version-info")
      def version_info():
          """
          :class:`flask:flask.Flask` route for retrieving version information about D-Tale
  
          :return: text/html version information
          """
          _, version = retrieve_meta_info_and_version("dtale")
          return str(version)
  
      @app.route("/health")
      def health_check():
          """
          :class:`flask:flask.Flask` route for checking if D-Tale is up and running
  
          :return: text/html 'ok'
          """
          return "ok"
  
      @app.url_value_preprocessor
      def handle_data_id(_endpoint, values):
          if values and "data_id" in values:
              # https://github.com/man-group/dtale/commit/536691d365b69a580df836e617978eb563402ac5
              values["data_id"] = get_url_unquote()(
                  values["data_id"]
              )  # for handling back-slashes in arcticDB symbols
              data_id_from_name = global_state.get_data_id_by_name(
                  values["data_id"]
              )
              values["data_id"] = data_id_from_name or values["data_id"]
  
      auth.setup_auth(app)
  
      with app.app_context():
          app = dash_views.add_dash(app)
          return app
  
imports: from __future__ import absolute_import, print_function
  import getpass
  import jinja2
  import logging
  import os
  import pandas
  import random
  import socket
  import sys
  import time
  import traceback
  from builtins import map, str
  from contextlib import closing
  from logging import ERROR
  from threading import Timer
  from werkzeug.routing import Map
  from flask import Flask, jsonify, redirect, render_template, request, url_for
  from flask.testing import FlaskClient
  import requests
  from flask_compress import Compress
  from six import PY3
  import dtale.auth
  import dtale.global_state
  import dtale.config
  from dtale import dtale
  from dtale.cli.clickutils import retrieve_meta_info_and_version, setup_logging
  from dtale.dash_application import views
  from dtale.utils import DuplicateDataError, build_shutdown_url, build_url, dict_merge, fix_url_path, get_host, get_url_unquote, is_app_root_defined, make_list, running_with_flask_debug
  from dtale.views import DtaleData, head_endpoint, is_up, kill, startup
label_desc: Use image node_id 2 for calling a global function with example usage: build_app(url, reaper_on, app_root, additional_templates) and returns: redirect, _root, _root, redirect, render_template, render_template,  int, render_template,  int, str, jsonify, str, str, app, unknown