def get_widgets(self, widget_width):
        """Creates and returns an address widget

        Args:
            widget_width (str): The width of all widgets to be created.

        Returns:
            Sequence[hdijupyterutils.ipywidgetfactory.IpyWidgetFactory]: list of widgets
        """
        ipywidget_factory = IpyWidgetFactory()

        self.address_widget = ipywidget_factory.get_text(
            description='Address:',
            value='http://example.com/livy',
            width=widget_width)
        widgets = [self.address_widget]
        return widgets
Esempio n. 2
0
    def __init__(self, shell, data=None, widget=None):
        # You must call the parent constructor
        super(RemoteSparkMagics, self).__init__(shell, data)

        self.endpoints = {}
        if widget is None:
            widget = MagicsControllerWidget(self.spark_controller, IpyWidgetFactory(), self.ipython_display)
        self.manage_widget = widget
Esempio n. 3
0
    def get_widgets(self, widget_width):
        """Creates and returns a list with an address, username, and password widget

        Args:
            widget_width (str): The width of all widgets to be created.

        Returns:
            Sequence[hdijupyterutils.ipywidgetfactory.IpyWidgetFactory]: list of widgets
        """
        ipywidget_factory = IpyWidgetFactory()

        self.user_widget = ipywidget_factory.get_text(description='Username:'******'Password:', value=self.password, width=widget_width)

        widgets = [self.user_widget, self.password_widget]
        return Authenticator.get_widgets(self, widget_width) + widgets
Esempio n. 4
0
    def __init__(self, df, encoding, renderer=None, ipywidget_factory=None, encoding_widget=None, ipython_display=None,
                 nested_widget_mode=False, spark_events=None, testing=False, **kwargs):
        assert encoding is not None
        assert df is not None
        assert type(df) is pd.DataFrame

        kwargs['orientation'] = 'vertical'

        if not testing:
            super(AutoVizWidget, self).__init__((), **kwargs)

        self.df = self._convert_to_displayable_dataframe(df)

        if renderer is None:
            renderer = GraphRenderer()
        self.renderer = renderer

        if ipywidget_factory is None:
            ipywidget_factory = IpyWidgetFactory()
        self.ipywidget_factory = ipywidget_factory

        if encoding_widget is None:
            encoding_widget = EncodingWidget(self.df, encoding, self.on_render_viz)
        self.encoding_widget = encoding_widget

        if ipython_display is None:
            ipython_display = IpythonDisplay()
        self.ipython_display = ipython_display

        self.encoding = encoding

        # Widget that will become the only child of AutoVizWidget
        self.widget = self.ipywidget_factory.get_vbox()

        # Create output area
        self.to_display = self.ipywidget_factory.get_output()
        self.to_display.width = "800px"
        self.output = self.ipywidget_factory.get_hbox()
        self.output.children = [self.to_display]

        self.controls = self._create_controls_widget()

        if spark_events is None:
            spark_events = AutoVizEvents()
        self._spark_events = spark_events

        if nested_widget_mode:
            self.widget.children = [self.controls, self.output]
            self.children = [self.widget]
        else:
            self.ipython_display.display(self.controls)
            self.ipython_display.display(self.to_display)

        self.on_render_viz()
 def __init__(self, shell, data=None, widget=None):
     super(DataprocMagics, self).__init__(shell, data)
     self.ip = self.shell
     self.db = self.ip.db
     self.endpoints = {}
     _restore_endpoints_and_sessions(self.db, self.ipython_display,
                                     self.spark_controller, self.endpoints)
     session_id_to_name = dict([
         (session.id, name) for name, session in  self.spark_controller.get_managed_clients().items()
     ])
     self.db['autorestore/' + 'session_id_to_name'] = session_id_to_name
     if len(self.endpoints) == 0:
         self.endpoints = None
     dataproc_widget = ControllerWidget(self.spark_controller, IpyWidgetFactory(),
                                        self.ipython_display, self.db, self.endpoints)
     widget = MagicsControllerWidget(self.spark_controller, IpyWidgetFactory(),
                                     self.ipython_display, self.endpoints)
     if self.endpoints is None:
         self.endpoints = {}
     self.manage_dataproc_widget = dataproc_widget
     self.__remotesparkmagics = RemoteSparkMagics(shell, widget)
     self.__remotesparkmagics.spark_controller = self.spark_controller
     self.__remotesparkmagics.ipython_display = self.ipython_display
Esempio n. 6
0
    def __init__(self, spark_controller, ipywidget_factory=None, ipython_display=None,
                 nested_widget_mode=False, testing=False, **kwargs):
        kwargs['orientation'] = 'vertical'

        if not testing:
            super(AbstractMenuWidget, self).__init__((), **kwargs)

        self.spark_controller = spark_controller

        if ipywidget_factory is None:
            ipywidget_factory = IpyWidgetFactory()
        self.ipywidget_factory = ipywidget_factory

        if ipython_display is None:
            ipython_display = IpythonDisplay()
        self.ipython_display = ipython_display

        self.children = []

        if not nested_widget_mode:
            self._repr_html_()
Esempio n. 7
0
    def __init__(self,
                 df,
                 encoding,
                 change_hook,
                 ipywidget_factory=None,
                 testing=False,
                 **kwargs):
        assert encoding is not None
        assert df is not None
        assert type(df) is pd.DataFrame

        kwargs['orientation'] = 'vertical'
        if not testing:
            super(EncodingWidget, self).__init__((), **kwargs)

        if ipywidget_factory is None:
            ipywidget_factory = IpyWidgetFactory()
        self.ipywidget_factory = ipywidget_factory

        self.df = df
        self.encoding = encoding
        self.change_hook = change_hook

        self.widget = self.ipywidget_factory.get_vbox()

        self.title = self.ipywidget_factory.get_html('Encoding:',
                                                     width='148px',
                                                     height='32px')

        # X view
        options_x_view = {str(i): str(i) for i in self.df.columns}
        options_x_view["-"] = None
        self.x_view = self.ipywidget_factory.get_dropdown(
            options=options_x_view, description="X", value=self.encoding.x)
        self.x_view.on_trait_change(self._x_changed_callback, 'value')
        self.x_view.layout.width = "200px"

        # Y
        options_y_view = {str(i): str(i) for i in self.df.columns}
        options_y_view["-"] = None
        y_column_view = self.ipywidget_factory.get_dropdown(
            options=options_y_view, description="Y", value=self.encoding.y)
        y_column_view.on_trait_change(self._y_changed_callback, 'value')
        y_column_view.layout.width = "200px"

        # Y aggregator
        value_for_view = self._get_value_for_aggregation(
            self.encoding.y_aggregation)
        self.y_agg_view = self.ipywidget_factory.get_dropdown(
            options={
                "-": Encoding.y_agg_none,
                Encoding.y_agg_avg: Encoding.y_agg_avg,
                Encoding.y_agg_min: Encoding.y_agg_min,
                Encoding.y_agg_max: Encoding.y_agg_max,
                Encoding.y_agg_sum: Encoding.y_agg_sum,
                Encoding.y_agg_count: Encoding.y_agg_count
            },
            description="Func.",
            value=value_for_view)
        self.y_agg_view.on_trait_change(self._y_agg_changed_callback, 'value')
        self.y_agg_view.layout.width = "200px"

        # Y view
        self.y_view = self.ipywidget_factory.get_hbox()
        self.y_view.children = [y_column_view, self.y_agg_view]

        # Logarithmic X axis
        self.logarithmic_x_axis = self.ipywidget_factory.get_checkbox(
            description="Log scale X", value=encoding.logarithmic_x_axis)
        self.logarithmic_x_axis.on_trait_change(self._logarithmic_x_callback,
                                                "value")

        # Logarithmic Y axis
        self.logarithmic_y_axis = self.ipywidget_factory.get_checkbox(
            description="Log scale Y", value=encoding.logarithmic_y_axis)
        self.logarithmic_y_axis.on_trait_change(self._logarithmic_y_callback,
                                                "value")

        children = [
            self.title, self.x_view, self.y_view, self.logarithmic_x_axis,
            self.logarithmic_y_axis
        ]
        self.widget.children = children

        self.children = [self.widget]
 def manage_dataproc(self, _line, _local_ns=None):
     """Magic that returns a widget for managing Spark endpoints and sessions for Dataproc."""
     self.manage_dataproc_widget = ControllerWidget(
         self.spark_controller, IpyWidgetFactory(), self.ipython_display, self.db, self.endpoints
     )
     return self.manage_dataproc_widget