Roman
Roman
SSolara
Created by hanne5005 on 12/29/2023 in #questions-issues
Solara for data manipulation application?
Hi, How is your project going? I am interested in doing something similar (reading database information, displaying it, and allowing users to write it through input components). As a newbie, I have ChatGPT supporting me. It suggested the following logic: functions with pre-written queries that are formatted after the user inputs something. The functions are called on value change/button click. It works well for reading tables and displaying them in dataframes (and using a search bar as a filter) as well as writing new lines in a table. However, modifying existing data is more challenging.
5 replies
SSolara
Created by Roman on 6/13/2024 in #questions-issues
Is it possible to update a df assigned to a reactive object without recreating it ?
(my bad for the incomplete example, it tested it in a notebook (in VSCode)) thanks for the solution I think I lack some python litteracy : why would my last example need to use a shallow copy while yours doesn't ?
13 replies
SSolara
Created by Roman on 6/13/2024 in #questions-issues
Is it possible to update a df assigned to a reactive object without recreating it ?
@MaartenBreddels tried something a little bit different and it doesn't work : the df doesn't get updated dynamically
from solara import *
import pandas as pd

df = solara.reactive(pd.DataFrame({'year' : [2025 + i for i in range(0, 10)]}))

start_pop = solara.reactive(100)
g_rate = solara.reactive(0.1)
r_rate = solara.reactive(0.95)

df_version = solara.reactive(0)

def copy_once():
df.value = df.value.copy()
solara.lab.on_kernel_start(copy_once)

@solara.component
def Population():

df_version.value

def update_pop():
df.value['population'] = [round(r_rate.value * start_pop.value*( 1+ g_rate.value)**i) for i in range(0, 10)]
df_version.value += 1

dff = df.value

with Columns([1,4]):
with Column():
InputInt('initial population', value=start_pop)
InputFloat('Growth rate', value=g_rate)
InputFloat('Retention rate', value=r_rate)
with Column():
Button('Update', on_click=update_pop)
DataFrame(dff)
from solara import *
import pandas as pd

df = solara.reactive(pd.DataFrame({'year' : [2025 + i for i in range(0, 10)]}))

start_pop = solara.reactive(100)
g_rate = solara.reactive(0.1)
r_rate = solara.reactive(0.95)

df_version = solara.reactive(0)

def copy_once():
df.value = df.value.copy()
solara.lab.on_kernel_start(copy_once)

@solara.component
def Population():

df_version.value

def update_pop():
df.value['population'] = [round(r_rate.value * start_pop.value*( 1+ g_rate.value)**i) for i in range(0, 10)]
df_version.value += 1

dff = df.value

with Columns([1,4]):
with Column():
InputInt('initial population', value=start_pop)
InputFloat('Growth rate', value=g_rate)
InputFloat('Retention rate', value=r_rate)
with Column():
Button('Update', on_click=update_pop)
DataFrame(dff)
13 replies
SSolara
Created by Roman on 6/13/2024 in #questions-issues
Is it possible to update a df assigned to a reactive object without recreating it ?
(access bloked by my company i'll have a look back home but thanks !!)
13 replies
SSolara
Created by Roman on 6/13/2024 in #questions-issues
Is it possible to update a df assigned to a reactive object without recreating it ?
by not working i mean that the df doesn't get updated while the list does
13 replies
SSolara
Created by Roman on 6/13/2024 in #questions-issues
Is it possible to update a df assigned to a reactive object without recreating it ?
but this doesn't : factor = solara.reactive(1) @solara.component def Page(): df_1['new'] = df_1['population'] * factor.value with Column(): InputInt('Factor', value=factor) DataFrame(df_1) Page()
13 replies
SSolara
Created by Roman on 6/13/2024 in #questions-issues
Is it possible to update a df assigned to a reactive object without recreating it ?
to give more context : no df example : factor = solara.reactive(1) @solara.component def Page(): population = [round( 100 *(1+0.1)**i) for i in range(0, 10)] new = [p * factor.value for p in population] with Column(): InputInt('Factor', value=factor) Markdown(str(new)) Page()
13 replies