import panel as pn
from awesome_panel_extensions.widgets.pivot_table import PivotTable # Please note you need to import extensions before you run pn.extension("perspective")
# Expected to work for Panel >= 0.10
# C.f. https://github.com/holoviz/panel/issues/1529#event-3682125861
# pn.extension("perspective")
# Works for Panel < 0.10
PivotTable.config()
pn.extension()
from awesome_panel_extensions.awesome_panel import notebook
notebook.Header(folder="examples/reference/widgets", notebook="PivotTable.ipynb")
PivotTable.js is provides an awesome interactive pivot tables and charts.
The PivotTable
widget enables the use of pivottable.js
in Panel apps.
value
(DataFrame): The data loaded to the viewer.The PivotTable
has the same layout and styling parameters as most other widgets. For example width
and sizing_mode
.
Let's start by importing the dependencies
import param
import pandas as pd
import panel as pn
import time
Let's load S&P500 financials data
# Source: https://datahub.io/core/s-and-p-500-companies-financials
DATA = "https://raw.githubusercontent.com/MarcSkovMadsen/awesome-panel/master/application/pages/awesome_panel_express_tests/PerspectiveViewerData.csv"
dataframe = pd.read_csv(DATA)
Let's create a PivotTable app to display the data
DARK_BACKGROUND = "rgb(42, 44, 47)" # pylint: disable=invalid-name
top_app_bar = pn.Row(
pn.layout.Spacer(width=10),
pn.pane.HTML("<h1 style='color:white'> PivotTable.js</h1>", align="center"),
pn.layout.HSpacer(),
pn.pane.PNG("https://panel.holoviz.org/_static/logo_horizontal.png", height=50, align="center"),
pn.layout.Spacer(width=25),
background=DARK_BACKGROUND,
)
# pn.config.sizing_mode = "stretch_width"
# Source: https://datahub.io/core/s-and-p-500-companies-financials
data = "https://raw.githubusercontent.com/MarcSkovMadsen/awesome-panel/master/application/pages/awesome_panel_express_tests/PerspectiveViewerData.csv"
dataframe = pd.read_csv(data)
columns = [
"Name",
"Symbol",
"Sector",
"Price",
"52 Week Low",
"52 Week High",
"Price/Earnings",
"Price/Sales",
"Price/Book",
"Dividend Yield",
"Earnings/Share",
"Market Cap",
"EBITDA",
"SEC Filings",
]
dataframe=dataframe[columns]
pivot_table = PivotTable(
height=500,
value=dataframe.copy(deep=True),
sizing_mode="stretch_width",
)
app = pn.Column(
top_app_bar,
pn.Row(
pivot_table,
sizing_mode="stretch_width",
),
height=800,
sizing_mode="stretch_width",
)
app