Py.Cafe

rob.on.lists/

solara-inventory-tracker-using_dummy_reactive

Editable Inventory Tracker, updates are displayed by using a dummy reactive value

DocsPricing
  • app.py
  • requirements.txt
app.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
# show map of messages, display map in Page() after a change

import solara
import pandas

store={'books':'3','shelves':'2','racks':'1'} # inventory
rstore_update = solara.reactive(0) # make inventory changes show up in frame

@solara.component
def MarkdownEditor(fld:str):
    md, set_md = solara.use_state(store[fld])
    def store_updater(newval):
        set_md(newval)
        store[fld]=newval  # update map
        rstore_update.set(rstore_update.value + 1)
        print(store)  # proof that on_value was triggered
    with solara.VBox() as main:
        solara.InputText('value '+fld,value=md, on_value=store_updater)
        solara.Markdown(md)
    return main

def show_frame(dummy):
    return pandas.DataFrame([store],index=['value']).T.reset_index().rename({'index':'item'},axis=1)

@solara.component
def Page():
    for fld in store.keys():
        MarkdownEditor(fld)
    # redisplay DataFrame after each change in store
    solara.DataFrame(show_frame(rstore_update.value))