code: def init_callbacks(dash_app):
      def save_chart(*args):
          args = list(args)
          save_clicks = args.pop(0)
          current_deletes = [
              args.pop(0) or 0 for _ in range(MAX_SAVED_CHARTS)
          ]
          inputs = args.pop(0)
          chart_inputs = args.pop(0)
          yaxis_data = args.pop(0)
          map_data = args.pop(0)
          cs_data = args.pop(0)
          treemap_data = args.pop(0)
          prev_save_clicks = args.pop(0)
          updated_configs = [
              args.pop(0) for _ in range(MAX_SAVED_CHARTS)
          ]
          prev_deletes = [
              args.pop(0) or 0 for _ in range(MAX_SAVED_CHARTS)
          ]
  
          delete_idx = None
          for i, (curr_delete, prev_delete) in enumerate(
              zip(current_deletes, prev_deletes)
          ):
              if curr_delete > prev_delete:
                  delete_idx = i
  
          if delete_idx is None:
              if save_clicks == prev_save_clicks:
                  raise DtalePreventUpdate
  
              config = dict_merge(
                  inputs,
                  chart_inputs,
                  dict(yaxis=yaxis_data or {}),
                  map_data,
                  cs_data,
                  treemap_data,
              )
  
              if not valid_chart(**config):
                  raise DtalePreventUpdate
  
              for index, saved_config in enumerate(updated_configs):
                  if saved_config is None:
                      updated_configs[index] = config
                      break
          else:
              updated_configs[delete_idx] = None
  
          return tuple(
              [save_clicks] + updated_configs + current_deletes
          )
  
      def load_saved_chart(_ts, config, prev_config):
          if config == prev_config:
              raise DtalePreventUpdate
          if config is None:
              return dict(display="none"), None, None, None
          if is_app_root_defined(
              dash_app.server.config.get("APPLICATION_ROOT")
          ):
              config["app_root"] = dash_app.server.config[
                  "APPLICATION_ROOT"
              ]
          charts, _, _, _ = build_chart(**config)
          return (
              dict(display="block"),
              charts,
              config,
              build_saved_header(config),
          )
  
      dash_app.callback(
          [Output("save-clicks", "data")]
          + [
              Output("saved-chart-config-{}".format(i), "data")
              for i in SAVED_CHART_IDS
          ]
          + [
              Output("saved-deletes-{}".format(i), "data")
              for i in SAVED_CHART_IDS
          ],
          [Input("save-btn", "n_clicks")]
          + [
              Input("delete-saved-btn-{}".format(i), "n_clicks")
              for i in SAVED_CHART_IDS
          ],
          [
              State("input-data", "data"),
              State("chart-input-data", "data"),
              State("yaxis-data", "data"),
              State("map-input-data", "data"),
              State("candlestick-input-data", "data"),
              State("treemap-input-data", "data"),
              State("save-clicks", "data"),
          ]
          + [
              State("saved-chart-config-{}".format(i), "data")
              for i in SAVED_CHART_IDS
          ]
          + [
              State("saved-deletes-{}".format(i), "data")
              for i in SAVED_CHART_IDS
          ],
      )(save_chart)
  
      for i in SAVED_CHART_IDS:
          dash_app.callback(
              [
                  Output("saved-chart-div-{}".format(i), "style"),
                  Output("saved-chart-{}".format(i), "children"),
                  Output(
                      "prev-saved-chart-config-{}".format(i), "data"
                  ),
                  Output("saved-chart-header-{}".format(i), "children"),
              ],
              [
                  Input(
                      "saved-chart-config-{}".format(i),
                      "modified_timestamp",
                  )
              ],
              [
                  State("saved-chart-config-{}".format(i), "data"),
                  State("prev-saved-chart-config-{}".format(i), "data"),
              ],
          )(load_saved_chart)
  
file_path: dtale/dtale/dash_application/saved_charts.py
imports: import dash_bootstrap_components
  from dash.dependencies import Input, Output, State
  from dtale.charts.utils import ANIMATION_CHARTS, ANIMATE_BY_CHARTS, ZAXIS_CHARTS
  from dtale.dash_application import dcc, html
  from dtale.dash_application.charts import build_chart, valid_chart
  from dtale.dash_application.exceptions import DtalePreventUpdate
  from dtale.dash_application.layout.utils import build_hoverable
  from dtale.utils import dict_merge, is_app_root_defined, flatten_lists, make_list
  from dtale.translations import text
label_desc: Use image node_id 3 for calling a global function with example usage: init_callbacks(dash_app) and returns: tuple, dict,  charts,  config,  build_saved_header, dict,  None,  None,  None