def view() -> pn.Column:
    """# Bootstrap Dashboard Page.

    Creates a Bootstrap Dashboard Page with a Chart and a Table

    - inspired by the [GetBoostrap Dashboard Template]
    (https://getbootstrap.com/docs/4.4/examples/dashboard/)
    - implemented using the `awesome_panel' Python package and in particular the
    `awesome_panel.express.templates.BootstrapDashboardTemplate`

    Returns:
        pn.Column -- The Orders View
    """
    table = pn.Pane(
        _get_table_data(),
        sizing_mode="stretch_width",
    )
    pn.config.sizing_mode = "stretch_width"
    main = [
        APPLICATION.intro_section(),
        pn.Column(
            pnx.SubHeader("Dashboard"),
            pn.pane.HoloViews(_holoviews_chart()),
        ),
        pn.Column(
            pnx.SubHeader("Section Title"),
            table,
        ),
    ]
    return pn.template.FastListTemplate(title="Bootstrap Dashboard",
                                        main=main,
                                        main_max_width="800px")
Beispiel #2
0
 def _selections(self, ):
     return pn.Column(
         pnx.SubHeader(" Selections"),
         self.param.all_endpoints,
         self._endpoints_widget,
         sizing_mode="fixed",
     )
    def _data(
        self,
    ):
        if self.attr_is_property:
            data = YahooQueryService.get_data(
                self.symbols,
                self.endpoint,
            )
        else:
            data = YahooQueryService.get_data(
                self.symbols,
                self.endpoint,
                self.frequency,
            )
        if isinstance(
            data,
            pd.DataFrame,
        ):
            # Enable formatters when https://github.com/holoviz/panel/issues/941 is solved
            # formatters = get_default_formatters(data)
            return pn.Column(
                pnx.SubHeader(" Response"),
                pn.widgets.DataFrame(
                    data,
                    fit_columns=True,
                    sizing_mode="stretch_width",
                    margin=25,
                ),
            )

        return pnx_json(data)
Beispiel #4
0
def test_headings():
    """We test that we can show

- headers: title, header, subheader
- aligned: left, center
"""
    return TestApp(
        test_headings,
        pnx.Title("Title Left"),
        pnx.Header("Header Left"),
        pnx.SubHeader("SubHeader Left"),
        pnx.Title("Title Center", text_align="center",),
        pnx.Header("Header Center", text_align="center",),
        pnx.SubHeader("SubHeader Center", text_align="center",),
        sizing_mode="stretch_width",
    )
Beispiel #5
0
    def _selections(self, ):
        if self.attr_is_property:
            parameters = ["endpoint"]
        else:
            parameters = [
                "endpoint",
                "frequency",
            ]

        return pn.Column(
            pnx.SubHeader(" Selections"),
            pn.Param(
                self,
                parameters=parameters,
                show_name=False,
                default_layout=pn.Row,
                widgets={
                    "endpoint": {
                        "width": 300
                    },
                    "frequency": {
                        "width": 100
                    },
                },
            ),
        )
Beispiel #6
0
def test_title_centered_white():
    """We test that we can show a centered Title, Header and SubHeader with a white text color"""
    return TestApp(
        test_title_centered_white,
        pnx.Title("Title Center", text_align="center", style={"color": "white"},),
        pnx.Header("Header Center", text_align="center", style={"color": "white"},),
        pnx.SubHeader("SubHeader Center", text_align="center", style={"color": "white"},),
        sizing_mode="stretch_width",
        background="lightgray",
    )
Beispiel #7
0
def test_with_url():
    """We test that we can show a Title with a link
"""
    return TestApp(
        test_with_url,
        pnx.Title("Title with url", url="https://awesome-panel.org",),
        pnx.Header("Header with url", url="https://awesome-panel.org",),
        pnx.SubHeader("SubHeader with url", url="https://awesome-panel.org",),
        sizing_mode="stretch_width",
    )
Beispiel #8
0
def view():
    """Run this to run the application"""
    set_environ()

    image_classifier_app = ImageClassifierApp()

    pn.config.sizing_mode = "stretch_width"

    main = [
        APPLICATION.intro_section(),
        pn.Column(
            pnx.SubHeader("Classifier"),
            pn.Param(
                image_classifier_app.param["model"],
                widgets={
                    "model": {
                        "type": pn.widgets.RadioButtonGroup,
                        "button_type": "primary",
                    }
                },
            ),
            pnx.SubHeader("Image"),
            pn.Param(
                image_classifier_app.param["image_file"],
                widgets={
                    "image_file": {
                        "type": pn.widgets.FileInput,
                        "accept": ".jpg",
                        "css_classes": ["pnx-fileinput-area"],
                        "height": 100,
                    }
                },
            ),
            image_classifier_app.predictions_view,
            pnx.SubHeader("Image"),
            image_classifier_app.image_view,
        ),
        image_classifier_app.resources_view,
    ]
    return pn.template.FastListTemplate(
        title="Image Classifier",
        main=main,
    )
Beispiel #9
0
def test_headings():
    """## test_headings

We test that we can show

- headers: title, header, subheader
- aligned: left, center
"""
    app = pn.Column(
        pn.pane.Markdown(test_headings.__doc__),
        pnx.Title("Title Left"),
        pnx.Header("Header Left"),
        pnx.SubHeader("SubHeader Left"),
        pnx.Title("Title Center", text_align="center"),
        pnx.Header("Header Center", text_align="center"),
        pnx.SubHeader("SubHeader Center", text_align="center"),
        sizing_mode="stretch_width",
        background="lightgray",
    )
    app.servable(test_headings.__name__)
Beispiel #10
0
 def predictions_view(self, ):
     """A view showing the predictions or the progress of the predictions"""
     if self.progress_value:
         return pn.Column(
             pnx.SubHeader("Prediction"),
             pn.widgets.Progress(
                 value=self.progress_value,
                 width=200,
             ),
             pn.pane.Str(self.progress_message),
             sizing_mode="stretch_width",
         )
     if self.top_predictions:
         return pn.Column(
             pnx.SubHeader("Prediction"),
             self.main_prediction_view,
             pnx.SubHeader("Alternative Predictions"),
             self.predictions_chart_view,
             sizing_mode="stretch_width",
         )
     return pn.pane.HTML()
def pnx_json(python_object: object) -> pn.viewable.Viewable:
    """Converts and json serialisabe object into Viewable

    Args:
        python_object (object): Any json serializable object

    Returns:
        pn.viewable.Viewable: [description]
    """
    return pn.Column(
        pnx.SubHeader(" Response"),
        pn.pane.JSON(python_object, depth=5, theme="light"),
    )
Beispiel #12
0
def code_card(code: str, ) -> pn.viewable.Viewable:
    """Wraps the code into a Card with "Code" as header and code as body

    Args:
        code (str): The code snippet to show

    Returns:
        pn.viewable.Viewable: A Card with "Code" as header and code as body.
    """
    return pn.Column(
        pnx.SubHeader(" Code"),
        Code(code),
    )
Beispiel #13
0
def view():
    """Run this to run the application"""
    set_environ()

    image_classifier_app = ImageClassifierApp()

    app = pn.Column(
        pnx.Header(
            "Image Classification with Keras and Tensorflow.",
            height=40,
        ),
        pn.pane.Markdown(__doc__),
        image_classifier_app.resources_view,
        pnx.SubHeader("Classifier"),
        pn.Param(
            image_classifier_app.param["model"],
            widgets={
                "model": {
                    "type": pn.widgets.RadioButtonGroup,
                    "button_type": "primary",
                }
            },
        ),
        pnx.SubHeader("Image"),
        pn.Param(
            image_classifier_app.param["image_file"],
            widgets={
                "image_file": {
                    "type": pn.widgets.FileInput,
                    "accept": ".jpg",
                }
            },
        ),
        image_classifier_app.image_view,
        image_classifier_app.predictions_view,
        sizing_mode="stretch_width",
    )
    return app
Beispiel #14
0
def test_with_url():
    """## test_with_url

We test that we can show a Title with a link
"""
    app = pn.Column(
        pn.pane.Markdown(test_with_url.__doc__),
        pnx.Title("Title with url", url="https://awesome-streamlit.org"),
        pnx.Header("Header with url", url="https://awesome-streamlit.org"),
        pnx.SubHeader("SubHeader with url",
                      url="https://awesome-streamlit.org"),
        sizing_mode="stretch_width",
        background="lightgray",
    )
    app.servable(test_with_url.__name__)
Beispiel #15
0
def pnx_help(python_object: object, ) -> pn.viewable.Viewable:
    """Helper function that convert a python object into a viewable help text

    Args:
        python_object (object): Any python object

    Returns:
        pn.viewable.Viewable: A Viewable showing the docstring and more
    """
    return pn.Column(
        pnx.SubHeader(" Documentation"),
        Code(
            str(python_object.__doc__),
            language="bash",
        ),
    )
Beispiel #16
0
 def _data(self, ):
     tickers = YahooQueryService.to_ticker(self.symbols)
     data = tickers.history(**self._history_args)
     if isinstance(
             data,
             pd.DataFrame,
     ):
         return pn.Column(
             pnx.SubHeader(" Response"),
             pn.pane.Vega(
                 self._history_plot(data),
                 sizing_mode="stretch_width",
                 height=325,
             ),
             sizing_mode="stretch_width",
         )
     return pnx_json(data)
Beispiel #17
0
    def __init__(  # pylint: disable=too-many-arguments
        self,
        pages: List[Union[pn.layout.Panel, pn.pane.Pane]],
        page_outlet: pn.layout.ListPanel,
        *args,
        css_classes: Optional[List[Optional[List[str]]]] = None,
        title: str = "Navigation",
        text_align: str = "center",
        sizing_mode: str = "stretch_width",
        **kwargs,
    ):
        """## Navigation Menu

        A widget composed of NavigationButtons that can be used to navigate between pages.

        Arguments:
            pages {List[Union[pn.layout.Panel, pn.pane.Pane]]} -- A list of 'pages' to navigate
                between. The first page in pages is selected by default.
            page_outlet {pn.layout.ListPanel} -- The ListPanel to update when the user navigates to
                a new page
        """
        if css_classes:
            pnx.fontawesome.extend()
            menuitems = [
                NavigationButton(page,
                                 page_outlet=page_outlet,
                                 css_classes=css)
                for page, css in zip(pages, css_classes)
            ]
        else:
            menuitems = [
                NavigationButton(page=page, page_outlet=page_outlet)
                for page in pages
            ]

        title = pnx.SubHeader(title, text_align=text_align)
        super().__init__(title,
                         *menuitems,
                         sizing_mode=sizing_mode,
                         *args,
                         **kwargs)

        page_outlet.clear()
        page_outlet.append(pages[0])
Beispiel #18
0
def test_title_centered_white():
    """## test_title_centered_white

We test that we can show a centered Title, Header and SubHeader with a white text color
"""
    app = pn.Column(
        pn.pane.Markdown(test_title_centered_white.__doc__),
        pnx.Title("Title Center",
                  text_align="center",
                  style={"color": "white"}),
        pnx.Header("Header Center",
                   text_align="center",
                   style={"color": "white"}),
        pnx.SubHeader("SubHeader Center",
                      text_align="center",
                      style={"color": "white"}),
        sizing_mode="stretch_width",
        background="lightgray",
    )
    app.servable(test_title_centered_white.__name__)