1
0

main.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import pandas as pd
  2. from pandas.api.types import is_bool_dtype, is_numeric_dtype
  3. from nicegui import ui
  4. df = pd.DataFrame(
  5. data={
  6. "col1": [x for x in range(6)],
  7. "col2": ["this", "column", "contains", "strings", "of", "text"],
  8. "col3": [x / 6 for x in range(6)],
  9. "col4": [True, False] * 3,
  10. }
  11. )
  12. def update(*, df: pd.DataFrame, r: int, c: int, value):
  13. df.iat[r, c] = value
  14. ui.notify(f"Set ({r}, {c}) to {value}")
  15. def home():
  16. with ui.row():
  17. for c, col in enumerate(df.columns):
  18. with ui.column():
  19. ui.label(col)
  20. for r, row in enumerate(df.loc[:, col]):
  21. with ui.row().classes("h-8 items-center"):
  22. if is_bool_dtype(df[col].dtype):
  23. cls = ui.checkbox
  24. elif is_numeric_dtype(df[col].dtype):
  25. cls = ui.number
  26. else:
  27. cls = ui.input
  28. cls(value=row, on_change=lambda event, r=r, c=c: update(df=df, r=r, c=c, value=event.value))
  29. home()
  30. ui.run(native=True)