code: def _preserve_output(
      self,
      explanation_name,
      visual,
      selector_key=None,
      file_name=None,
      **kwargs,
  ):
      from plotly.offline import iplot, plot, init_notebook_mode
      from IPython.display import display, display_html
      from base64 import b64encode
  
      from plotly import graph_objs as go
      from pandas.core.generic import NDFrame
      import dash.development.base_component as dash_base
  
      init_notebook_mode(connected=True)
  
      def render_html(html_string):
          base64_html = b64encode(html_string.encode("utf-8")).decode(
              "ascii"
          )
          final_html = """<iframe src="data:text/html;base64,{data}" width="100%" height=400 frameBorder="0"></iframe>""".format(
              data=base64_html
          )
          display_html(final_html, raw=True)
  
      if visual is None:  # pragma: no cover
          msg = "No visualization for explanation [{0}] with selector_key [{1}]".format(
              explanation_name, selector_key
          )
          _log.error(msg)
          if file_name is None:
              render_html(msg)
          else:
              pass
          return False
  
      if isinstance(visual, go.Figure):
          if file_name is None:
              iplot(visual, **kwargs)
          else:
              plot(visual, filename=file_name, **kwargs)
      elif isinstance(visual, NDFrame):
          if file_name is None:
              display(visual, **kwargs)
          else:
              visual.to_html(file_name, **kwargs)
      elif isinstance(visual, str):
          if file_name is None:
              render_html(visual)
          else:
              with open(file_name, "w") as f:
                  f.write(visual)
      elif isinstance(visual, dash_base.Component):  # pragma: no cover
          msg = "Preserving dash components is currently not supported."
          if file_name is None:
              render_html(msg)
          _log.error(msg)
          return False
      else:  # pragma: no cover
          msg = (
              "Visualization cannot be preserved for type: {0}.".format(
                  type(visual)
              )
          )
          if file_name is None:
              render_html(msg)
          _log.error(msg)
          return False
  
      return True
  
imports: from abc import ABC, abstractmethod
  import logging
  from ._environment import EnvironmentDetector, is_cloud_env, ENV_DETECTED
  from .._version import __version__
label_desc: Use image node_id 2 for calling the PreserveProvider obj's underlying member method code with example usage: obj._preserve_output(explanation_name, visual, selector_key, file_name) and returns: True, False, False, False