|
@@ -1,38 +1,32 @@
|
|
|
|
+#!/usr/bin/env python3
|
|
import pandas as pd
|
|
import pandas as pd
|
|
from pandas.api.types import is_bool_dtype, is_numeric_dtype
|
|
from pandas.api.types import is_bool_dtype, is_numeric_dtype
|
|
|
|
|
|
from nicegui import ui
|
|
from nicegui import ui
|
|
|
|
|
|
-df = pd.DataFrame(
|
|
|
|
- data={
|
|
|
|
- "col1": [x for x in range(6)],
|
|
|
|
- "col2": ["this", "column", "contains", "strings", "of", "text"],
|
|
|
|
- "col3": [x / 6 for x in range(6)],
|
|
|
|
- "col4": [True, False] * 3,
|
|
|
|
- }
|
|
|
|
-)
|
|
|
|
|
|
+df = pd.DataFrame(data={
|
|
|
|
+ 'col1': [x for x in range(4)],
|
|
|
|
+ 'col2': ['This', 'column', 'contains', 'strings.'],
|
|
|
|
+ 'col3': [x / 4 for x in range(4)],
|
|
|
|
+ 'col4': [True, False, True, False],
|
|
|
|
+})
|
|
|
|
|
|
|
|
|
|
def update(*, df: pd.DataFrame, r: int, c: int, value):
|
|
def update(*, df: pd.DataFrame, r: int, c: int, value):
|
|
df.iat[r, c] = value
|
|
df.iat[r, c] = value
|
|
- ui.notify(f"Set ({r}, {c}) to {value}")
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def home():
|
|
|
|
- with ui.row():
|
|
|
|
- for c, col in enumerate(df.columns):
|
|
|
|
- with ui.column():
|
|
|
|
- ui.label(col)
|
|
|
|
- for r, row in enumerate(df.loc[:, col]):
|
|
|
|
- with ui.row().classes("h-8 items-center"):
|
|
|
|
- if is_bool_dtype(df[col].dtype):
|
|
|
|
- cls = ui.checkbox
|
|
|
|
- elif is_numeric_dtype(df[col].dtype):
|
|
|
|
- cls = ui.number
|
|
|
|
- else:
|
|
|
|
- cls = ui.input
|
|
|
|
- cls(value=row, on_change=lambda event, r=r, c=c: update(df=df, r=r, c=c, value=event.value))
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-home()
|
|
|
|
-ui.run(native=True)
|
|
|
|
|
|
+ ui.notify(f'Set ({r}, {c}) to {value}')
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+with ui.grid(rows=len(df.index)+1).classes('grid-flow-col'):
|
|
|
|
+ for c, col in enumerate(df.columns):
|
|
|
|
+ ui.label(col).classes('font-bold')
|
|
|
|
+ for r, row in enumerate(df.loc[:, col]):
|
|
|
|
+ if is_bool_dtype(df[col].dtype):
|
|
|
|
+ cls = ui.checkbox
|
|
|
|
+ elif is_numeric_dtype(df[col].dtype):
|
|
|
|
+ cls = ui.number
|
|
|
|
+ else:
|
|
|
|
+ cls = ui.input
|
|
|
|
+ cls(value=row, on_change=lambda event, r=r, c=c: update(df=df, r=r, c=c, value=event.value))
|
|
|
|
+
|
|
|
|
+ui.run()
|