<jupyter_start><jupyter_text>Using the WidgetEnv class By the end of this tutorial you should be able to do the following:            Create an instance of the WidgetEnv class for a given python object.                                    Use the df_args/df_kwargs parameters of                     WidgetEnv (WidgetEnv.__init__) to customise the WidgetEnv.                            Use the subenv method to create WidgetEnv             instances from objects stored withing an WidgetEnv.    Use the update method to update an instance of the WidgetEnv class inplace.    Use the buttons featured by the WidgetEnv interface.    Use the out argument and changeout method to change a         WidgetEnv's attached output.<jupyter_code>from env_explore import WidgetEnv<jupyter_output><empty_output><jupyter_text>An instance of class the  `ExampleClass`, from ``tutorial_utils`` will be used thoughout this tutorial.<jupyter_code>from tutorial_utils import ExampleClass
eg = ExampleClass()<jupyter_output><empty_output><jupyter_text>**1** - Create an instance of the ``WidgetEnv`` class for a given python object.The ``WidgetEnv`` class inherits from the ``EnvHandler`` class and is initialised using the same parameters.See EnvHandler_tutorial.ipynb.The minimimum input required is the ``name`` argument.  This is a string that can be evaluated as code in the current enviromentto create the ``env`` attribute.The code below creates a WidgetEnv for the ``ExampleClass`` instance, ``eg`` using all given parameter defaults.<jupyter_code>we = WidgetEnv('eg')
we<jupyter_output><empty_output><jupyter_text>**1.a** - Use parameters to customise the WidgetEnv``name`` (``str``): Name by which the object can be referenced in the main enviroment.    ``display_as`` (``str``): Name of the attribute to be displayed by the ``_ipython_display_`` method (default = ``'df'``).``df_args`` (``Iterable``): Positional arguments for ``self.setdf`` (default = ``{}``). ``df_kwargs`` (``dict``): Key word arguments for ``self.setdf`` (default = ``{}``).    ``html_args`` (``Iterable``): Positional arguments for ``self.sethtml`` (default = ``[]``).    ``html_kwargs`` (``dict``): Key word arguments for ``self.sethtml`` (default = ``{}``).  **1.a. Example 1** - Choose the columns of the WidgetEnvThe ``df_kwargs`` or (``df_args``) argument can be used to determine the columns in the ``EnvHandler.df`` Dataframe.The code below creates an EnvHandeler for the ``ExampleClass`` instance, ``eg`` which has extra columns.<jupyter_code>df_kwargs = {
    'funcs': {'Type': type, 'Times 2': lambda x: x*2},  # {column_name: function}
    'attrs': {'Documentation': '__doc__', 'Real': 'real'}  # {column_name: attribute_name}
}

df_args = df_kwargs.values()

# the two objects displayed should be identical
display(
    WidgetEnv('eg', df_kwargs=df_kwargs), # using df_kwargs
    WidgetEnv('eg', df_args=df_args) # using df_args
)<jupyter_output><empty_output><jupyter_text>**2** - Using the ``update`` methodIf the result of evaluating the ``name`` attribute changes, the ``update`` method can be used to update the WidgetEnv accordingly.Note that ``name``, ``df_args`` and ``df_kwargs`` arguments used to create an EnvHandler in 1.a. Example 2 can be used in the same way by ``update``.The code below will set a new attribute, ``f``, of our ``ExampleClass`` instance ``eg`` with value ``'New Attribute'`` before calling the ``update``.  Notice how our WidgetEnv ``we`` now has an extra row with index ``'f'``.<jupyter_code>eg.f = 'New Attribute'
we.update()
we<jupyter_output><empty_output><jupyter_text>**3** - Using the ``subenv`` methodThe subenv method can be used to create an EnvHandler from an attribute of the ``env`` of an existing EnvHandler.Note that ``df_args`` and ``df_kwargs`` arguments used to create an EnvHandler in 1.a. Example 2 can be used in the same way by ``update``.  **3 Example 1** - Use the update method to create an EnvHandler from ``eg.b``.<jupyter_code>we.subenv('b') # roughly equivilant to EnvHandler('eg.b')<jupyter_output><empty_output><jupyter_text>**3 Example 2** - Use the update method to create an EnvHandler from ``eg.a.imag``.<jupyter_code>we.subenv(['a', 'imag']) # roughly equivilant to EnvHandler('eg.b.imag') or we.subenv('a').subenv('imag')<jupyter_output><empty_output><jupyter_text>**4** - Using the WidgetEnv's InterfaceThe default WidgetEnv interface has 3 types of button:            Cell Buttons        Clicking on these buttons displays their value in the output.                Clear Button        Clicking on this button clears the output.                Update Button        Clicking on this button updates the WidgetEnv by calling its update method (See Section 2).    Try it out below.<jupyter_code>we<jupyter_output><empty_output><jupyter_text>**5** - Using the ``out`` argument and ``changeout`` method The code below generates and displays two seperate WidgetEnvs.Notice that when you click a cell button in one of the WidgetEnv, the value is displayed in the output of both.Similarly when you click the clear button of either WidgetEnv, the output of both is cleared.<jupyter_code>wes = (WidgetEnv('eg'), WidgetEnv('5'))
display(*wes)<jupyter_output><empty_output><jupyter_text>This is because they share the same default output generated when the ``env_explore`` module was imported near the begining of the notebook.We use the ``changeout`` methon to change the WidgetEnv's output.Notice that the two WidgetEnvs above no longer share an output.<jupyter_code>from ipywidgets import Output

wes[0].changeout(out=Output())
display(*wes)<jupyter_output><empty_output><jupyter_text>We can also use the ``changeout`` method to have a specified WidgetEnvs share outputs.In the code below, ``we1`` and ``we3`` share a single output whilst ``we2`` has its own.<jupyter_code>from env_explore import getmain
we1, we2, we3 = WidgetEnv('eg'), WidgetEnv('eg'), WidgetEnv('eg')

we1.changeout(Output())
we2.changeout(Output())
we3.changeout(we1.out)

display(we1, we2, we3)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11579296615792967, 'fraction_numerical': 0.0058062375580623755, 'mean_word_length': 4.904995102840353, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '342993', 'license': 'MIT', 'n_tokens_mistral': 1748, 'n_tokens_neox': 1746, 'n_words': 680, 'path': 'tutorials/WidgetEnv_tutorial.ipynb', 'repo_name': 'nuki111/env_explore', 'size': '6028'}