|
| 1 | +import polars as pl |
| 2 | +from setup import append_info, load_data, save_info |
| 3 | +from shiny import reactive |
| 4 | +from shiny.express import app_opts, input, render, ui |
| 5 | + |
| 6 | +with ui.sidebar(): |
| 7 | + ui.input_text("name_input", "Enter your name", placeholder="Your name here") |
| 8 | + ui.input_checkbox("checkbox", "I like checkboxes") |
| 9 | + ui.input_slider("slider", "My favorite number is:", min=0, max=100, value=50) |
| 10 | + ui.input_action_button("submit_button", "Submit") |
| 11 | + |
| 12 | +# Load the initial data into a reactive value when the app starts |
| 13 | +data = reactive.value(load_data()) |
| 14 | + |
| 15 | + |
| 16 | +# Append new user data on submit |
| 17 | +@reactive.effect |
| 18 | +@reactive.event(input.submit_button) |
| 19 | +def submit_data(): |
| 20 | + info = { |
| 21 | + "name": input.name_input(), |
| 22 | + "checkbox": input.checkbox(), |
| 23 | + "favorite_number": input.slider(), |
| 24 | + } |
| 25 | + # Update the (in-memory) data |
| 26 | + d = data() |
| 27 | + data.set(append_info(d, info)) |
| 28 | + # Save info to persistent storage (out-of-memory) |
| 29 | + save_info(info) |
| 30 | + # Provide some user feedback |
| 31 | + ui.notification_show("Submitted, thanks!") |
| 32 | + |
| 33 | + |
| 34 | +# Data grid that shows the current data |
| 35 | +@render.data_frame |
| 36 | +def show_results(): |
| 37 | + return render.DataGrid(data()) |
0 commit comments