-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-core.py
58 lines (48 loc) · 1.61 KB
/
app-core.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from itables.sample_dfs import get_dict_of_test_dfs
from itables.widget import ITable
from shiny import App, reactive, render, ui
from shinywidgets import output_widget, reactive_read, render_widget
dfs = get_dict_of_test_dfs()
app_ui = ui.page_sidebar(
ui.sidebar(
ui.input_select(
"table_selector",
"Table",
choices=list(dfs.keys()),
selected="int_float_str",
)
),
output_widget("my_table"),
ui.markdown("Selected rows"),
ui.output_code("selected_rows"),
title="Using the ITable Widget in a Shiny App",
fillable=True,
)
def server(input, output, session):
@render_widget
def my_table():
"""
This function creates the "my_table" widget. While we could
pass the df or the other arguments here, it's nicer
to use a "reactive.effect" to update the widget
"""
return ITable(caption="A table rendered with ITable", select=True)
@reactive.effect
def _():
"""
This "reactive.effect" uses the "update" method of the ITable widget
to update the widget with the new inputs.
"""
# Get the new inputs
df = dfs[input.table_selector()]
selected_rows = list(range(0, len(df), 3))
# Update the widget
my_table.widget.update(df, selected_rows=selected_rows)
ui.markdown("Selected rows")
@render.code
def selected_rows():
"""
Here we read the "selected_rows" attribute of the ITable widget
"""
return str(reactive_read(my_table.widget, "selected_rows"))
app = App(app_ui, server)