Skip to content

Commit

Permalink
Merge pull request #434 from apjanusz/main
Browse files Browse the repository at this point in the history
Added table widget (#433)
  • Loading branch information
pplonski authored Mar 20, 2024
2 parents 395202f + a446c95 commit d4073f4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions mercury/mercury.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from widgets.in_mercury import in_mercury
from widgets.user import user
from widgets.pdf import PDF
from widgets.table import Table

def print_version():
try:
Expand Down
1 change: 1 addition & 0 deletions mercury/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ boto3==1.26.83
cryptography
pyopenssl>=23.1.1
bleach>=6.0.0
itables>=2.0.0
25 changes: 25 additions & 0 deletions mercury/widgets/table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from itables import show

import ipywidgets
from IPython.display import display
from .manager import WidgetsManager

import warnings


def Table(data=None, width="auto", text_align="center"):
if data is None:
raise Exception("Please provide data!")

if "DataFrame" not in str(type(data)):
raise Exception("Wrong data provided! Expected data type is 'DataFrame'.")

if "%" in width:
raise Exception("Wrong width provided! You can't provide value using '%'.")

if text_align not in ["center","left","right"]:
raise Exception("Wrong align provided! You can choose one of following options: 'left', 'right', 'center'.")

text_align= f"dt-{text_align}"
show(data, classes=["display", "cell-border"], columnDefs=[{"className":text_align,"width":width,"targets":"_all"}])

0 comments on commit d4073f4

Please sign in to comment.