def test_card_with_code(): """We test that we can create a card with code content""" code = """\ card = pnx.Card("Code", pnx.Code(code),) return TestApp(test_card_collapsable, card)""" card = pnx.Card("Code", pnx.Code(code)) return TestApp(test_card_with_code, card, width=600)
def test_card_with_multiple_panels(): """We test that we can create a card with - A header with lightgray background - A Plot Body - A Text Body - A Plot Body - A Text Body Please note that due to some Bokeh formatting I've not been able to create a divider line that stretches to full width. """ card = pnx.Card( "Card With Plot", [ _holoviews_chart(), "Awesome Panel! " * 50, _holoviews_chart(), "Awesome Panel! " * 50, ], width=600, ) return TestApp( test_card_with_multiple_panels, card, )
def test_card_collapsable(): """We test that we can create a collapsable card with - A header with lightgray background - A Plot Body - A Text Body Please **note** that - the header text and collapse button text are not vertically aligned. I have yet to figure that out. - I have not been able to use the *chevron down* with a *rotation* transition like at [Card Collapse Tricks](https://disjfa.github.io/bootstrap-tricks/card-collapse-tricks/) - When you click the collabse button, the button is shown for a short while. I would like to remove that but I do not yet know how. - I would like to change the collapse button callback from a Python callback to JS callback. """ card = pnx.Card( "Card with Plot", [ _holoviews_chart(), "Awesome Panel! " * 50, ], collapsable=True, width=600, ) return TestApp( test_card_collapsable, card, )
def _selections(self, ): if self.attr_is_property: parameters = ["endpoint"] else: parameters = [ "endpoint", "frequency", ] return pnx.Card( "Selections", pn.Param( self, parameters=parameters, show_name=False, default_layout=pn.Row, widgets={ "endpoint": { "width": 300 }, "frequency": { "width": 100 }, }, ), )
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 pnx.Card( "Response", pn.widgets.DataFrame( data, fit_columns=True, sizing_mode="stretch_width", margin=25, ), ) return pnx_json(data)
def _selections(self, ): return pnx.Card( "Selections", [ self.param.all_endpoints, self._endpoints_widget, ], sizing_mode=None, )
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 pnx.Card( "Code", pnx.Code(code), )
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 pnx.Card( "Response", pn.pane.JSON(python_object, depth=5, theme="light"), )
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 pnx.Card( "Documentation", pnx.Code( str(python_object.__doc__), language="bash", ), )
def test_card_with_plot(): """We test that we can create a card with - A header with lightgray background - A Plot Body And the card it self is has a fixed width """ card = pnx.Card( "Card With Plot", _holoviews_chart(), width=600, ) return TestApp( test_card_with_plot, card, )
def test_card(): """We test that we can create a card with - A header with lightgray background - A Body And the card it self is full width responsive by default. """ card = pnx.Card("Card - Header and Body", TEXT, sizing_mode="stretch_width") return TestApp( test_card, card, width=600, background="ghostwhite", )
def test_card_fixed_width(): """We test that we can create a card with - A header with lightgray background - A Body And the card it self is fixed to 300px """ card = pnx.Card( "Card - Fixed Width", TEXT, width=300, sizing_mode="fixed", ) return TestApp( test_card_fixed_width, card, background="ghostwhite", )
def _data(self, ): tickers = YahooQueryService.to_ticker(self.symbols) data = tickers.history(**self._history_args) if isinstance( data, pd.DataFrame, ): return pn.Column( pnx.Card( "Response", body=pn.pane.Vega( self._history_plot(data), sizing_mode="stretch_width", height=325, ), ), sizing_mode="stretch_width", ) return pnx_json(data)
def _data(self, ): data = YahooQueryService.get_data( self.symbols, "option_chain", ) if isinstance( data, pd.DataFrame, ): # Enable formatters when https://github.com/holoviz/panel/issues/941 is solved # formatters = get_default_formatters(data) # We also show the first 5 columns as other wise the app gets too slow. return pnx.Card( "Response", pn.widgets.DataFrame( data.head(), fit_columns=True, sizing_mode="stretch_width", margin=25, ), ) return pnx_json(data)