Skip to content

Commit

Permalink
Add example
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Apr 11, 2024
1 parent 6771e78 commit b40bec4
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions docs/examples/edit_data/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pandas as pd
from pytabulator import (
TableOptions,
Tabulator,
TabulatorContext,
output_tabulator,
render_tabulator,
)
from pytabulator.utils import create_columns
from shiny import App, reactive, render, ui

df = pd.DataFrame({"id": [1, 2, 3], "name": ["Hans", "Peter", "Hanna"]})
table_options = TableOptions(columns=create_columns(df, default_editor=True))

app_ui = ui.page_auto(
ui.h1("Edit data and submit changes", style="padding-top: 10px;"),
output_tabulator("tabulator"),
ui.div(ui.input_action_button("submit", "Submit data"), style="padding-top: 10px;"),
)


def server(input, output, session):
@render_tabulator
def tabulator():
return Tabulator(df, table_options)

@reactive.Effect
@reactive.event(input.submit)
async def trigger_get_data():
async with TabulatorContext("tabulator") as table:
print("get data")
table.trigger_get_data()

@reactive.Effect
@reactive.event(input.tabulator_data)
def tabulator_data():
df_submitted = pd.DataFrame(input.tabulator_data())
print(df_submitted)


app = App(app_ui, server)

0 comments on commit b40bec4

Please sign in to comment.