def test_get_default_formatters(): """A manual test of the `pnx.widgets.dataframe.get_default_formatters` function applied to a DataFrame. We expect to see to see a `pn.widgets.DataFrame` with - ints aligned right, with zero decimals and ',' as thousands separator - floats aligned right, with two decimals and ',' as thousands separator - strings aligned left """ data = pd.DataFrame( {"int": [1, 2, 3000,], "float": [3.14, 6.28, 9000.42,], "str": ["A", "B", "C",],}, index=[1, 2, 3,], ) formatters = dataframe.get_default_formatters(data) code = pnx.Code( """\ data = pd.DataFrame( {"int": [1, 2, 3000], "float": [3.14, 6.28, 9000.42], "str": ["A", "B", "C"]}, index=[1, 2, 3], ) formatters = dataframe.get_default_formatters(data)""" ) return TestApp( test_get_default_formatters, pn.widgets.DataFrame(data, formatters=formatters,), code, )
def test_card_with_code(): """We test that we can create a card with code content""" code = """\ card = pn.layout.Card("Code", pn.layout.Code(code),) return TestApp(test_card_collapsible, card)""" card = pn.layout.Card(pnx.Code(code), header="Code") return TestApp(test_card_with_code, card, width=600)
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 plotly_view(*args, **kwargs) -> pn.Column: """## Dashboard Orders Chart View based on Plotly""" fig = plotly_chart() return pn.Column( pnx.Header("Plotly"), pn.Row(pn.layout.HSpacer(), pn.pane.Plotly(fig), pn.layout.HSpacer(),), pnx.InfoAlert("Plotly cannot currently auto size to full width and be responsive"), pnx.Code(code=inspect.getsource(plotly_chart)), sizing_mode="stretch_width", name="Plotly", *args, **kwargs, )
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 holoviews_view() -> pn.Column: """## Dashboard Orders Chart View based on HoloViews""" fig = holoviews_chart() text = """ The [HoloViews](http://holoviews.org/) and [hvplot](https://hvplot.pyviz.org/) I had not used before. Their APIs are different than what I'm used to be also seems powerfull. I'm used to Plotly but it does not work well in Panel yet. """ return pn.Column( pnx.Header("Holoviews"), fig, pn.pane.Markdown(text), pnx.Code(inspect.getsource(holoviews_chart)), name="Holoviews", sizing_mode="stretch_both", )
def test_code(): """A manual test of the Code pane. We expect to see nicely formatted Python code inside a gray box.""" code = """\ def my_add(a,b): return a+b """ return TestApp( test_code, pnx.Code( code, language="python", ), sizing_mode="stretch_width", )